How to Display Last Updated Posts in WordPress


Whenever you update a post in your WordPress blog, WordPress stores the date time of that update. So, you can use this date to display posts on the basis of last update time. We have already posted how to display recent posts or display recent posts from a specific category. In this post, we will see how to display recently updated posts.

Open functions.php of the theme and add following code.

function WTips_lastupdated() {

$lastupdated = array(
'orderby' => 'modified',
'ignore_sticky_posts' => '1'

$lastupdated_loop = new WP_Query( $lastupdated );
$counter = 1;
echo '<ul>';
while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post();
echo '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>';
echo '</ul>';

add_shortcode('lastupdated-posts-wt', 'WTips_lastupdated');

Above code is written only to display 5 posts. You can change the $counter limit to any value for increasing or decreasing number of posts.

Best WordPress Hosting with Bluehost

Now you only need to use this function when you want to display last updated posts. Just use the code given below on the page where you want to display posts.


if (function_exists(WTips_lastupdated)) :

If you have copied every thing right, you will see last updated posts.

You have already created shortcode for this. So, you can also display last updated posts with this shortcode [lastupdated-posts-wt].

Source: wpbeginner

Get your free WordPress blog here

Tags: |
Nord VPN Sale

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Similar Articles

2020 UseThisTip | Developed By Deepanker