• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero Blog

NameHero Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • VPS Hosting
    • WordPress Hosting
    • WooCommerce Hosting
  • Reseller
  • Enterprise
  • Domains
  • Account
  • Blog Home
  • Categories

How To Sort Posts By The “Last Modified” Date

Bhagwad Park

Published on: January 11, 2023

Categories: WordPress 2

I’m updating a bunch of older posts on my site, and I’m trying to see which posts have gone the longest without modifications. Unfortunately, WordPress’s list of posts and pages can only be sorted by “Date”, which means the date of publication. There’s no in-built way to create a new column called “Modified Date” and sort by that.

So here are two ways to sort WordPress posts and pages by the “modified date” instead of the publication date. The first one is easy and doesn’t require any coding. The second method includes code to paste into your theme’s functions.php.

Method 1: The Easy Way – No Coding Required

If you’re not looking for a permanent solution and want the WordPress admin dashboard to sort your posts or pages by the modified date once in a while, then there’s no need to use a plugin or fiddle around with code. You need to change the URL that appears when you sort by “Date”.

Navigate to the list of posts or pages, and click the “Date” column, so that it sorts the posts by the date of publication. Now modify the URL and replace “date” with “modified” and change the order to “asc” instead of “desc” like this:

https://www.example.com/blog/wp-admin/edit.php?orderby=modified&order=asc

Modify the URL to Sort by Modified Date in Ascending Order
Modify the URL to Sort by Modified Date in Ascending Order

Naturally, you want to replace “example.com/blog” with the name of your WordPress website. Loading the above URL will sort the entries on the current page by the modified date. Setting the “order” parameter to “asc” will give you the oldest posts to have been modified, and “desc” will show you the most recently modified posts first.

Neat huh?

Method 2: Adding Code to Sort by the Modified Date

If you’re looking for a more permanent solution, add the following code to your theme’s functions.php file:

function sort_by_modified( $wp_query ) {
	global $pagenow;
	if ( is_admin() && 'edit.php' == $pagenow) {
		$wp_query->set( 'orderby', 'modified' );
		$wp_query->set( 'order', 'ASC' );
	}
}
add_filter('pre_get_posts', 'sort_by_modified' );

If you don’t know how to add code to WordPress like this, read my tutorial on how to add code to WordPress without a plugin.

The above code changes the query on the backend of the WordPress admin that lists the posts or pages and shows a new one instead. True, the interface becomes a bit misleading because you get the impression that it’s sorting posts by the date instead of the modified date, but who cares? I’m not going to figure out how to change the name of the date column for cosmetic reasons!

Sorting by the Modified Date is Critical for SEO Maintenance

I’ve just realized that I have several posts on my site WP-Tweaks.com that are several years old. Most of these are tutorials, so their information is still relevant, but some things can be refreshed. The screenshots with better resolution reflect the changes in the WordPress editor with Gutenberg, new image WEBP formats, product descriptions, and titles.

For this kind of SEO task, sorting the posts in order of the last modified date is a godsend. I prefer to use the URL method of sorting the posts since I only need to do it once in a while, and I think that will be true for most people. After all, why change something permanently when the requirement is so niche?

You need to use the coding solution only if you have a compelling reason to always sort the posts by the modified date. I hope you found this tutorial helpful!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Reader Interactions

Comments

  1. jack says

    March 21, 2023 at 10:46 am

    function sort_by_modified( $wp_query ) {
    global $pagenow;
    if ( is_admin() && ‘edit.php’ == $pagenow) {
    $wp_query->set( ‘orderby’, ‘modified’ );
    $wp_query->set( ‘order’, ‘ASC’ );
    }
    }
    add_filter(‘pre_get_posts’, ‘sort_by_modified’ );

    this is only for “if is admin” … what if you want to make it show the order by modified for anyone who comes on your site, register and unregistered users.

    Reply
    • CornElDos says

      May 3, 2023 at 8:47 am

      I would think just removing is_admin would do it

      function sort_by_modified( $wp_query ) {
      global $pagenow;
      if ( ‘edit.php’ == $pagenow) {
      $wp_query->set( ‘orderby’, ‘modified’ );
      $wp_query->set( ‘order’, ‘ASC’ );
      }
      }
      add_filter(‘pre_get_posts’, ‘sort_by_modified’ );

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!

Most Popular Posts

Speed up your site: solving the WordPress slowdown

NameHero’s Recommended WordPress Plugin and Theme Setup (2023)

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • Website Performance
  • Web Hosting
  • Resellers
  • Website Development
  • Website Security
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Domains
Help & Support
  • NameHero Blog
  • Knowledgebase
  • Announcements
  • Affiliates
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2023 NameHero, LLC. All rights reserved.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA