Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Display a List of Last Updated Posts in WordPress

At WPBeginner, we show last modified date instead of original published date for all of our articles. We think it is bad idea to remove dates from your WordPress blog posts. If you are using last modified date, then you might want to show a list of your recently updated posts on your site. In this article, we will show you how to display a list of last updated posts in WordPress.

Each time you update a post, WordPress stores the date and time of that update in the posts table as last updated date. We will show you how to create a custom WordPress query to list your most recently updated articles.

Copy and paste this code in a site-specific plugin or your theme’s functions.php file.

function wpb_lastupdated_posts() { 

// Query Arguments
$lastupdated_args = array(
'orderby' => 'modified',
'ignore_sticky_posts' => '1'

//Loop to display 5 recently updated posts
$lastupdated_loop = new WP_Query( $lastupdated_args );
$counter = 1;
$string .= '<ul>';
while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post();
$string .= '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>';
$string .= '</ul>';
return $string;

//add a shortcode
add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');

That’s all. Now if you want to display last updated posts in your theme’s template files, then you can use it like this:

if (function_exists(wpb_lastupdated_posts)) : 

To display last updated posts in WordPress posts, pages, and widgets, then you can use the shortcode [lastupdated-posts].

There are many different ways to sort your articles in WordPress. Aside from the ascending, descending, and random order, you can also display posts by expiration date. With this article, you can now show posts by the last modified time.

How would you use this on your site? Are you displaying original published date or last modified date? Let us know by leaving a comment below.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

33 CommentsLeave a Reply

    • You would want to check with your eCommerce plugin for what options they would recommend as they normally have a widget or similar option.


    • If you are using the code from this article, you would change the 5 to a 30 for that :)


  1. Thank you for the instructions. That was exactly what I was looking for! Finally I can show the latest updates in my sidebar.

  2. Hi,

    It works well, but it does not respect the content permissions of the page. It turns all the content visible to anybody…

  3. Hi,

    I followed you ‘How to Create a Custom WordPress Widget’, including ‘Creating a Site-Specific WordPress Plugin’ and that works perfectly. Great tutorial as I now have the ‘Hello world’ text displaying as a sidebar.

    But this one has me completely stumped. I followed the tutorial as best I could but it just displays my ‘Hello world’ text, never any list of updated posts.

    Where in my custom plugin file do I put the function wpb_lastupdated_posts()? Where do I put the ‘add_shortcode’ and where do I put the ‘if (function_exists(wpb_lastupdated_posts)) : ‘ statement?

    Many thanks,

  4. Installed the code as stated. When using the short code- I add it to the bottom of the post. but when view the code- it puts the information on the top of the post. weird.

    • Same request here. I’m interested in listing recently updated Pages + showing the last_modified date. Ideally with some excerpt or number of characters from page.

  5. Great code, but is there anyway to get this exact same function but based on comments made by specific user (admin) and list the most recent comment made as the top of the threads in the list?


  6. Hi… great post…. Yet I was wondering if you could give me a hand on something: I need to take the picture and title of the last three published posts and arrange them in some kind of Gallery (Just to show the latest three published articles, Any idea if there’s a plugin for that, I assume I can use the code you just placed above, but Im not quite sure on the DB structure)

    Thanks in advance… =)

  7. Hello

    By the way nice article, so I have a doubt.

    Where to put this code:


    thank you

  8. I do not know how to change the office location address on my WordPress web site. Try as I may, I cannot reach it to change it. I would appreciate simple and straight answer. I can do most of the upkeep but that address change eludes me and i have not seen the key in the WP information and tutorials. help.

    • @Pierre your office location is stored inside a widget. Inside your WordPress admin area, go to Appearance » Widgets. On your right hand column you will see a list of widgets currently in use on your site. Look for Footer Widget Area and there you will see Get in Touch widget which you can edit and save your changes.


  9. Hi, love this article but I don’t quite get what is meant to be updated when you mention ‘use it like this:

    Which file is this?


    • Some users might want to display last updated posts into different templates of their WordPress themes. Those users can use this code to add it. Other users can use the shortcode to add it in their posts, pages, and widgets.


  10. Instead of using $counter for your loop, why don’t you just use the 'posts_per_page' attribute on the WP_Query args ?

    Mine goes like this:

    $lastupdated_args = array(
    ‘orderby’ => ‘modified’,
    ‘ignore_sticky_posts’ => 1,
    ‘posts_per_page’ => 5

    Also, when I try the above code, it only give me one last modified post (not five as it should be).
    Wonder why …

  11. I love your articles but this one is way over my head. Are there any plugins for this? :)

    Sorry but I dont know the “innards” of the website and have broken my site when I tried a few things.

    It is a great idea though.Thanks for all you great work. Mary

    • The code above is actually a ‘plugin’. Simply copy and paste the first code in functionality plugin. Then, there are two ways to display the list of posts, either using template tag or the easiest, using [lastupdated-posts] shortcode.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.