Family Best Time >> Electronics

How to display a list of the latest updated posts in WordPress

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

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

Copy and paste this code into a site specific plugin or your theme funciones.php proceedings.

 función wpb_lastupdated_posts () // Argumentos de consulta $ lastupdated_args = array ('orderby' => 'modified', 'ignore_sticky_posts' => '1'); // Loop para mostrar 5 publicaciones actualizadas recientemente $ lastupdated_loop = new WP_Query ($ lastupdated_args); $ contador = 1; $ cadena. = '
    '; while ($ lastupdated_loop-> have_posts () && $ counter the_post (); $ string. = '
  • post-> ID). '">' .get_the_title ($ lastupdated_loop-> post-> ID). '('. get_the_modified_date (). ')
  • '; $ contador ++; al final $ cadena. = '
'; devuelve $ cadena; wp_reset_postdata (); // agregar un código corto add_shortcode ('lastupdated-posts', 'wpb_lastupdated_posts');

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

 

To display the latest updated posts in WordPress posts, pages and widgets, you can use the shortcode [Últimos mensajes actualizados] .

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

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