I’m having some difficulty to find an example of how to create a loop with posts that had been updated in the last 24 hours.
My idea is to have a page of posts or perhaps on the index.php a lists of posts that had been updated in the last day (24 hours from the time the query is done)
Is this possible ? Is there any way to perform that query ?
Thanks in advance
Depending on where you want your posts to show, the solution will vary. If you want to filter your main homepage, this solution will do:
Note that we remove the filter because we don’t want to limit every posts query run on the site. Only our relevant ones.
If you want to filter a query other than the main home query, just change the conditional within the
pre_get_posts
function.If you want to filter a sub-query, it’s even simpler, just add the
posts_where
filter before your instantiation of WP_Query, and remove it immediately after, and skip thepre_get_posts
bit.