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:
- The next_posts_link() works only with original $wp_query
- WP_Query: Why is sticky post not first item in loop?
- Query *only* sticky posts
- Skipping first 3 posts in wp query
- Accessing the post content with WP_Query
- Get only modified posts
- How to output comments number of a post per day?
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- If specific user role then sticky post
- Hide Post comments when displayed via WP_Query
- Display posts with comments closed, with pagination?
- posts_per_page doesnt work
- I want to query posts in monthly basis
- Custom WP_QUERY $args
- Improving WP_Query for performance when random posts are ordered
- Why won’t my taxonomy query show up?
- How to find what index page a post is on?
- Display post from current category and same tag?
- Get Posts that are in the current month or later
- WP Query to Get Array of Slugs
- WP_Query with ajax handler returns the same posts
- Why WP_Query(‘showposts=5’) shows only 1 post?
- How can I sort posts by the date and a custom meta field?
- Hiding Draft Post In Admin
- How to insert 2 args into 1 Wp_Query for a slideshow
- How to verify wp user password by sql query in wp? [closed]
- WP Query – Posts Per Page not working in combination with category__in
- How to filter my search in post if contains a word in title, content or excerpt?
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- Query posts and return XML
- how to change the number of posts returned in a specific loop without making it global?
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- Adding a blog archive with pagination using WP_Query
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- Why Query is returning empty array?
- Ignore latest two posts
- Show posts by author of membership level (Paid Membership Pro)
- meta_value timestamp older than now
- Print out last 3 blogposts
- Query for first 3 posts to change the look and feel
- Why posts array is empty?
- Getting blog pagination to work on page set as front page
- How to group only VISIBLE posts? [closed]
- How to check in functions.php if there is data in a WP_Query?
- Shortcode with ‘year’ parameter
- search blog posts by author first name and or last name
- On what hook can I get the queried object’s final state?
- unique post in “$args” of wp_query display more than one post
- If no posts exist for current day and month, show the next available day of posts
- How to display post list in a table layout (multiple queries in single loop)
- Not all posts showing in query
- Get all custom posts with a certain taxonomy
- Link to date_query results in WordPress
- Query function not executed between element [closed]
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- WordPress query portfolio posts
- Get latest author posts inside the loop
- Limiting post list by taxonomy
- Display 3 posts with different HTML markup using a loop
- Is there a function to get post info for any publish_status by post ID?
- How Can I Always Display A Particular Post First Using WP_Query?
- How to show multiple posts thumbnail, title and date in widget
- Group first, 2nd, 3rd, etc posts by category terms
- Manipulated offset and pagination, can’t display last post anymore
- Function is printing twice – any suggestions?
- How to display particular set of wordpress post on a webpage?
- Order posts inside bootstrap card columns
- How to use two query result together in one loop
- show loop id post , only first id can read
- Page with Category Returning 1
- filter posts based on menu_order
- Show 5 posts and than 3 posts offset with pagination
- Change archive results based on GET request
- Get 5 most recent categories
- Wp_query loop is not working as it should
- Show all posts from the tags without having to set all of them
- Is it possible to query a category with specified posts?
- Is there a global page/post/product/anything ID?
- WordPress loop uses unmodified posts array, why?
- wp query custom orderby not custom field
- 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?
- Remove duplicated posts in the loop if post has more than one category
- Retrieve latest post by multiple categories with ID
- How to Include a common category in a custom Category Search
- Why I getting only 1 post?
- The next_posts_link() works only with original $wp_query
- Limit amount of pages shown in pagination within wp_query
- custom sort posts in archive/taxanomy page
- First post in loop displays twice
- Trying to create shortcode listing custom posts, but formating not being included
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Get posts after calculating meta key
- Get related posts matching most of the provided tags using WP_Query
- WP_Query post_tilte search in posts table