You can improve by storing the “expiry” time of post as a meta instead of the publish time. This way you can query for posts with meta which is smaller then the current time and draft them, no need to loop over all posts.
Drawback is that you will have to decide how to handle changes to lifespawn time, just ignore this edge case or adjust all posts.
Related Posts:
- How to limit the number of posts that WP_Query gets?
- Should we trust the post globals?
- Get current post id in functions.php
- Get first post from wp_query
- WP_Query offset argument does not work
- Querying post from a multisite network
- How to know if get_posts() failed?
- Show related posts by category but ignore one category
- post__in for get_posts with a dynamic array
- Keep getting same permalink with WP_Query?
- Query posts distinct authors
- How to query posts with current or future date only
- Pagination not working on Custom Page Template
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Post content being duplicated by the_content();
- How to add padding between posts
- prevent showing posts of an specific category in admin posts section
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- How to change bulk post status
- Add few specific post ids to wp_query
- Custom Order in WP Query
- Search query – exact post title match
- WP_Query posts_per_page ignored
- How to get most recent commented post above new submitted post in WordPress?
- wp_query ‘s’ parameter does not work with custom post type
- How to start with post number x?
- WP_Query get posts from custom posts by category
- Accessing post->ID outside of the loop for listing child pages
- WP Query – duplicated posts once including tags in search results
- List posts in a given category
- Reset Popular post query?
- Query Posts multiple conditions
- how to get posts ids inside pre_get_posts filter?
- Future post ID not showing
- How do I use WP_Query to get a range of posts with custom fields that have numbers with letters in them?
- recent posts for different categories
- Search by post title and content in wp_query without order
- Change post order random through out the entire WordPress
- Setup a custom dynamic post
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- Removing noindex posts from wp_query
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Exclude the first ‘n’ number of posts of a tag from home page?
- how to change the number of posts returned in a specific loop without making it global?
- posts_per_page option limits the number of Gallery items
- Nested WP_Query breaking loop
- Why Query is returning empty array?
- meta_value timestamp older than now
- Get posts with multiple categories
- Do not show children of a category
- Query for first 3 posts to change the look and feel
- Getting blog pagination to work on page set as front page
- search blog posts by author first name and or last name
- unique post in “$args” of wp_query display more than one post
- Display current post position in Elementor Posts widget
- How to give classname to post if post has no content?
- Custom wp-query in wordpress rest api
- posts_per_page returning only one post
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- How to retrieve certain number of images from a wordpress post?
- WordPress post filter menu
- How to display post list in a table layout (multiple queries in single loop)
- Not all posts showing in query
- WP_Query custom field pass the post id
- WordPress query portfolio posts
- Current and next month posts
- Get latest author posts inside the loop
- Same post appears in related Posts?
- Display 3 posts with different HTML markup using a loop
- How to show multiple posts thumbnail, title and date in widget
- WP_Query outputs wrong post in custom post type
- how to show comments only author which send own posts in wordpress
- Group first, 2nd, 3rd, etc posts by category terms
- Manipulated offset and pagination, can’t display last post anymore
- How to sort WP_Post Object array by object field in php?
- Order by meta_key field in WordPress not meta_value field value
- How to display particular set of wordpress post on a webpage?
- How to create page with post content in it?
- How to remove a post from results by ID after query?
- Show 5 posts and than 3 posts offset with pagination
- Override wp_link_pages pagebreak with filter
- WP_Query extended with AJAX
- Is it possible to query a category with specified posts?
- Blog only showing one post even though more published
- WordPress loop uses unmodified posts array, why?
- Sort / Filter Queries
- Show posts between two Custom Fields date
- Query to get data of a post, if in category?
- Order posts by custom field
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How do I control the fallback query after the original query returned cero posts?
- Remove duplicated posts in the loop if post has more than one category
- Order posts by separate menu order for different sub-categories
- Adding a category at even positions on main loop with modified pagination
- Why I getting only 1 post?
- What is wrong with this wp_query?
- Exclude sub sub categories from displaying in the archive page
- First post in loop displays twice
- date_query returning only the most recent post instead of the post published before today
- Is it possible to use the_post 2 times in one loop