how do I include those posts that don’t have an entry?
You can include those posts (which do not have the expire_date
field/meta) by adding a second clause with 'compare' => 'NOT EXISTS'
, and then set the relation
to OR
:
$query_args['meta_query'] = array(
// the relation between the root clauses/queries; defaults to AND
'relation' => 'OR',
array( // root clause/query 1
'key' => 'expire_date',
'value' => date("Y-m-d"),
'type' => 'DATE',
'compare' => '>=',
),
array( // root clause/query 2
'key' => 'expire_date',
'compare' => 'NOT EXISTS',
),
);
So actually, you just needed to remove lines 15 and 9 in the code in question.
Related Posts:
- How to store and receive variables in WP sessions?
- Nested meta_query with multiple relation keys
- WP_Query vs get_posts
- Reduce or prevent calling of update_meta_cache
- Query Multiple Post types each with own meta query
- Order wp_query by calculated field
- new WP_Query() – what is the earliest valid hook?
- Extending WP_Query — Optimise SQL query
- Display only posts with thumbnail using WP_Query
- Why is my WP_Query not working when tax_query terms are an array?
- WP_query and pagination?
- pagenavi with merged wp_query [duplicate]
- How can I display recent posts from a particular category in my header?
- Select posts with any post_type from database?
- Search Custom Post with meta_value NULL
- Ajax Infinite Scroll In Custom WP_Query Loop Not Working
- Query two post types and order by two different date fields
- How to display images in related posts?
- WP Query – Get WooCommerce Products with variation that is in stock
- Multiple search queries on one page
- How to Modify Taxonomy Archive Page with Search Parameter?
- $wpdb->insert inserting two rows in database
- Custom Post order for homepage
- Arrange BBpress topics by created
- Warnings in nav-menu when visiting query pages [closed]
- Page navigation doesn’t show when query category
- Sorting posts DESC based on the number of comments using WP_Query
- Create unique page without header.php for json feed
- $wpdb select date range of posts
- Meta Query relation “AND” not working
- get_posts() not working with multiple statuses
- Add quicklink to in the Admin posts page where I can query by a meta_key
- Performance when getting post meta for post retrieved by meta value
- Exclude an array
- WP_Query: “post_parent” and “post_type” combination returning strange results
- How to use the query hook/filter?
- Cutom wp_query for geolocation search, pagination not working
- Tax query AND/OR meta query [duplicate]
- WP_query return more results than SQL query. post_count > found_posts
- Help ordering Post loop by two meta values
- Display most popular in the past two days
- WP_Query (list) posts according to author’s custom field
- Need to convert string of term ids into comma separated integers for use in an arguments array
- How can I allow sticky posts but cap the query to 1 post?
- Hide posts with meta key in WP_Query
- How do I get my custom query to work with search results after the first page?
- Need Sub-category with main Category
- Easy way to write complex queries in wordpress
- Error with function in functions.php?
- I am having problem sorting custom post type using WP_Query
- difference between querying database and using the loop
- Query_vars support in Rest API
- How to do logical OR in terms in WP Query?
- Continue or break the while loop
- Custom query filter by ACF date custom field
- Child pages not affected by orderby
- Write WP Query that selects posts that are part of the same two categories
- Error in meta_query not get result
- Sorting posts by Multiple custom fields in defined order
- Custom wp_query – I’m getting ‘all’ post, not the specific post in the query
- Phpmyadmin – post editing
- Show multiple tax_query from 2 or more post_type in a single code
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- Query not sorting DESC
- How to use rewind_comments() – when and how to use it?
- How to make a query returning pages from multiple parents
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- create a custom query for posts managed by Restrict Content Pro
- meta_query – check for multiple meta values in key which holds an array of values
- How to sort wordpress posts already selected by WP_QUERY
- How do I stop the same post showing multiple times in a archive?
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- WP_Query on custom key and value
- Set “editor” role to existing user
- how to get wp_query posts only first letter of alphabet A?
- How to mix two orderby-parameters into one ordered result
- Custom Post Type WP_Query with filters and search
- Merge wp-query and get_users
- Get posts by similar names and categories
- Query by meta value (add a dropdown of all values)
- WP Query issue for multiple values
- Calling a function with WP_Query only ever brings the first result
- get last child post by wp_query
- How To Query All Attachment Images Found In Post Galleries
- WordPress meta_query not working
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Filter WP_Query output before it is accessed (pre_get_posts)?
- $wp_query when new WP_Query
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Divide WP_Query posts by date & post type
- Unable to pass variable
- WP Query get posts by specific author IDs if one of several logged in authors
- New WordPress WP Query using posts from certain categories
- Edit WordPress loop, taxonomies, & filter
- WP query based on two meta queries
- SQL query into to WP query
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- I want to place a post before all others from an ACF boleen field
- How to put posts with some taxonomy on top of others in `pre_get_posts`