In your loop while(have_posts() ) : the_post();
you are unconditionally going through all posts, but since the loop stops after the_post()
nothing actually happens. So that’s where the condition has to go:
while(have_posts() ) {
the_post();
if ($daysleft >= 0) {
... other actions
}
}
Your code looks a bit incomplete to me, so I’m not sure if my exact code will work, but this definitely is where you want the condition.
Please note that if the query has returned, for instance, 15 posts you may have less displayed if some of them are expired. If you want a fixed amount displayed, you must not change the loop which displays the result of the query, but the query itself.
Related Posts:
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- How do I remove all the metaboxes for a custom post type?
- Get all posts from custom post type and insert in select input as metabox
- Detect meta value changes when post is updated (post_updated)
- Permalinks using event date (year & month) instead of publication date
- Grossly inefficient wordpress loops!
- How to sort CPT by custom meta value (date), and return posts month by month
- Having trouble with custom post type / meta box
- How can I include meta box content when searching?
- update a post meta from a single table cell TablePress
- update custom post type meta from a shortcode
- Custom Meta Boxes – Nonce Issue – Move to trash issue
- Displaying Meta Box Image
- How to keep a check box in custom meta box for custom post type checked by default for add new post?
- How to add multiple featured image in meta box in post editor?
- Show metabox in custom-post-template depending on taxonomy term?
- Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
- Display custom post on home page based on a metabox selection
- Displaying Metabox value (custom post type taxonomy)
- How can I display my custom metaboxes on a custom post template?
- Meta Box Only in CPT Edit Page, Not in Add New
- get_post_meta is returning image id
- get_template_part() – post-meta not working?
- Create a random unique 6 digit number as custom field for custom post type
- Populate Custom Fields in a Custom Post Type?
- Custom meta box data array: foreach not working correctly?
- Undefined Variable – Custom Post Type Meta
- Populate dropdown from one custom post type inside another custom post type
- Meta Key Value in current-user-only loop
- How to check if user meta field is empty in conditional else statement
- A better way to add a meta box to custom post types
- Metabox not show in categories custom post type cmb2
- Show Custom Post Type meta boxes only on Page Edit
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Meta Data for Custom Post Type not saving
- create custom meta box with default value
- Displaying a div from an assigned meta_value when on a page
- Create Array from custom post type to display a slider
- How to Echo Metadata Value in Currency Format
- Issue on Working with Metabox – Checkbox to enable Sale Items
- Why do I have to press the “Update” button twice to save my meta box values?
- Values from meta-box not on $_POST
- Custom post type suddenly stoped working after WordPress 5 update
- How can I output WPAlchemy repeating fields meta values in my page template?
- Meta box data is saved but NOT displayed in the meta box text field. Why?
- Save Metabox Custom Field Value
- Meta box data not saving
- WP_Meta_Query object with conditionals
- WordPress giving a 404 page when passing a year argument different than the current year
- Related posts meta_query CPT
- Meta box with front-end styling
- Sanitaizing Select Optin For Custom Post Type Metabox in WP
- Cannot Save MetaBox Data in Custom Post Type
- Add a class to post_class if more than one post shares same meta_value_num
- Function to return values from metabox
- Add a meta field to the list of results for a custom post type
- Empty meta-box returns publishdate if no value is set?
- Custom Meta Box with variable number of fields
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- How to avoid duplicate posts queried from custom meta?
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Get meta values from parent post and save in child post
- Metaboxes in Loop
- Custom meta box data not saving
- Collect custom post in a calendar
- get_post_meta for Custom Post Type ( CPT )
- Delete custom post type metadata without deleting the post in admin area
- How to check if meta box value is false for all posts then do something based on that
- Loop posts in a table ordered by a custom field value
- Problem with ‘save_post’ hook not running
- How to get past and upcoming post by defining date in custom field?
- Edit post meta direct from post.php?
- Howto: use existing post_meta as options for a different metabox (checkboxes or list)
- How to create content automatically when a post is published?
- Display a post count from a custom metabox selection
- loop through custom post-type with two meta_keys
- Post AND page parameter for WP function
- why get_post_meta is returning 0?
- Show search for data extracted from metabox
- Use a Variable in update_post_meta as the $meta_key
- Adding custom post type to loop
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- Taxonomy posts on Archive page
- How to best delete orphan wp_postmeta
- Custom Post Type Metabox – Not Saving
- WordPress Orderby Numeric Value Not Working
- Replace title column in post list with post meta value
- Show one item per category of a custom post type
- Multiple Loops On Custom Post Type Template?
- Add Standard Page Attributes Metabox for Page Parent
- Post count by month of taxonmy term
- Custom Post Type within the Loop on Homepage (Page Template)
- updating one custom meta field only
- How to retrieve custom post type permalink in another cpt?
- Search form to find custom meta box generated data
- Custom Loop and Standard Blog Loop Issue
- Custom post type – update_meta not working
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Group search results by post type, but having a unique heading for each section?