Sort posts by most recently modified

Is there a way to list posts in the order in which they were modified?

For example;

Read More

A user posts 5 posts (#1 being the oldest and #5 being the newest), by default they would be listed with #5 being at the top, but say the user edited post #3 at a later date, is it possible to then list post #3 above #5 without manually changing the page attributes?

This is a secondary query by the way, using get_posts

Related posts

Leave a Reply

1 comment

  1. If you use WP_Query you can set the orderby to modified and then the order to DESC and you’ll be good to go. If it’s not a custom query, you can just use the set() method on the default $wp_query global to do the same. Since get_posts() is just a wrapper for WP_Query, you can set the orderby parameter there if everything else is working and not change anything else.