manski's blog

Sort posts by modification date in WordPress

By default, WordPress sorts blog posts by creation date. However, if you update your blog posts from time to time, you may want to sort them by modification date rather than creation date.

To achieve this, use this snippet:

function order_posts_by_mod_date($orderby) {
  if  (is_home() || is_archive() || is_feed()) {
    $orderby = "post_modified_gmt DESC";

  return $orderby;

add_filter('posts_orderby', 'order_posts_by_mod_date', 999);

In your theme, just dump this snippet into functions.php. (You may need to create this file in your theme’s directory.)


  1. George said: ∞

    It works great, Ive been looking EVERYTHING on the internet for the answer, after 50 different results, nothing. Thank you so much for this!

  2. Quy P. said: ∞

    Thank you so much. The code works really well on my wordpress site. I also replaced the creation date -> modified date in the entry-meta.

  3. Hong Hanh said: ∞

    Thank you so much. This saved me hours and hours of searching. It works well on my site.

Leave a Reply

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