09
Nov
How to Show a List of Last Updated Posts in WordPress
- Category:
- Wordpress

Posted On : November 9, 2013
| No Comment
When You update any post in wordpress admin side , WordPress always stores the date and time of that update in the posts table as last updated date in database.
So Here We will show you how to create a custom WordPress query for displaying a list of your most recently updated posts of your site.
Step 1: Copy below given code in function.php file of your theme
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Function last_updated_posts() { // Arguments of Query $arg_of_LastUpdated = array( 'orderby' => 'modified', 'ignore_sticky_posts' => '1' ); //Loop for displaying 4 recently updated posts $loop_of_lastupdated = new WP_Query( $arg_of_LastUpdated ); $count = 1; echo '<ul>'; while( $loop_of_lastupdated->have_posts() && $count < 5 ) : $loop_of_lastupdated->the_post(); echo '<li><a href="' . get_permalink( $loop_of_lastupdated->post->ID ) . '"> ' .get_the_title( $loop_of_lastupdated->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>'; $count++; endwhile; echo '</ul>'; wp_reset_postdata(); } //Add a Shortcode for displaying in posts or pages add_shortcode('Last_Updated_Posts', 'last_updated_posts'); |
Step 2: you can display last updated posts in your theme’s template files by adding given below code.
1 2 3 | if (function_exists(last_updated_posts)) : last_updated_posts (); endif; |
Step 3: you can also display last updated posts in your wordpress posts, pages or widgets by adding given below code.
[Last_Updated_Posts]
Here We have added a short-code in wordpress widget:
At front-Side it will display like that in sidebar:
- Tags: