• Hello,

    I want to show recent modified/updated posts in sidebar using wordpress recent posts widget. I don’t want to show recent published instead I want to show recent updated/modified posts.

    Can anyone please provide me code snippet to add in functions.php to get my required result ?

    Thanks in Advance.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Sorry, no specific snippet. I can recommend using the “pre_get_posts” action hook to alter the query being made so that the most recently modified posts are queried instead of the default. There are several example snippets on the linked doc page that you could use as a starting point.

    One significant challenge in using pre_get_posts is applying your changes only to this one specific query and not any others. The examples all have an if() statement limiting application, but no example is suitable for a specific block query.

    The best way to distinguish the query you want to target is to look at other query object properties that would distinguish the query from all others.

    The other plausible technique would be to identify some other action that occurs just before the query executes. Add your pre_get_post callback from that action, then have your callback remove itself from the action stack once it has done its modifications so it does not affect subsequent queries.

Viewing 1 replies (of 1 total)
  • The topic ‘How to show recent updated/modified posts using recent posts widget ?’ is closed to new replies.