In the case that the start_date
custom field only exists for the event
post type, this works:
$query->set( 'meta_query', array(
'relation' => 'OR',
array(
'key' => 'start_date',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'start_date',
'value' => $today = date( 'Ymd' ),
'compare' => '>=',
),
array(
'key' => 'end_date',
'value' => $today = date( 'Ymd' ),
'compare' => '>=',
),
) );
By comparing the start_date
key to NOT EXISTS
, the other post types are not filtered out. Obviously this is not an ideal solution, so I’m still curious if there are better ideas out there.
Related Posts:
- How can I create a meta_query with an array as meta_field?
- How can I query all users who registered today?
- WordPress creating excessive joins on meta_query with search
- How to display liked posts of current user in wordpress?
- How do I find if a page has a template?
- How to check current user in meta value array in WP_Query meta_query
- Query metas (and not : query posts by metas)
- How to orderby multiple meta fields with another meta query
- Query returning same results even though the ID changes
- Order by meta value pro first then meta value free in my search function
- get_users with array as meta_value
- get_post_meta with WP_query
- WordPress Mysql query and Duplicate
- How to “orderby” the first array in a meta_query that uses multiply keys?
- meta_query not working
- WordPress query: merge meta key (number) values and sort
- Restrict WordPress search to a single ACF field
- Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
- Fastest and most efficient SQL query to check if UID exists
- Query Posts that have or don’t have a meta_value and order by the same ASC
- What is the best way to query posts based on live data?
- list or get meta_key where meta_value is ‘something’
- WP_Query orderby meta key/value suddely stopped working
- Meta Query compare with LIKE pulls similar post types: 55 and 155, and 1,155
- Custom query_var causes displaying posts archive on front page
- What is the most efficient way of implementing a favorite post system?
- Why does get_the_time(‘F j’) return November 30 for all posts?
- Query by one meta_key and sort by another (possibly NULL value)
- Query & Sort Comments by custom comment meta
- is_archive() doesn’t work on public query var archive pages?
- How to count get_users query?
- Possible to get posts from multiple meta keys/values in a single query?
- Difference between fragment caching and wp_cache
- mysql query paging
- How to display all posts with today’s same month and day only?
- Two differents queries in archive page
- Meta Query for specific months
- get_posts() loop returns the same the_title() for each post
- How to set back query var author_name after unset it?
- My SQL function to change user_name
- How to retrieve elements from another table in a SQL query?
- WordPress Loop: List All Posts by a Category & Subcategory
- Order query by post meta value
- Query posts if meta key starts with
- List all posts from past week grouped by sub-category
- Query Custom Post Type posts by Keyword/url slug
- how would I create a custom query to get all users, and a related post based on a postmeta field?
- Display posts with a start OR end date later than current date
- Help with MySQL to $WPDB query
- Order posts by custom field DATE value
- Form redirect with query vars to page
- Query to Get All Users from wp_users With NO matching user_id In wp_usermeta
- WordPress custom setting page – add flashing message
- Custom query AFTER rss fetch_feed not working
- Multiple Category Query
- list all categories that have a certain word in title
- Passing parameters to a static front page
- wp_list_pages() refuses to output posts
- Where is the query in wp-login.php
- Can’t seem to do combined query AND sort?
- Order posts by recent comments
- query if page has not child
- sort query results by newest
- How to reset usual $query on search page to push custom $wpdb query there?
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- Custom Query returns array, but I can’t see it’s elements
- How to delete all posts, categories and tags from WordPress database
- Ideas how to search & replace post_content when string contains a newline?
- How to insert Collate into WordPress search query?
- Query the WordPress database to get data together with replaced information
- $wpdb->prepare affecting the query?
- WordPress SQL search, how to handle SQL Injection?
- Optimize slow SQL query for multiple meta values
- Query for Custom Post Type UI Does Not Loop All the Post
- Updating with $qpdb->query() always returns 0 rows affected
- How to manage a particular “order by” for get_search_query()?
- Query to view scheduled or draft post
- How to return count of custom post type posts with a specific custom field value via $wpdb?
- Help with Related Posts Function
- How to add a Variable to post query
- Sort a list of a CPT ( job) if a meta is empty
- Restore WordPress Backup Locally?
- post type => ‘any’ not applied my custom queries
- Trouble migrating custom post types from non-wordpress cms
- “order” does not affect order of custom query
- Create a new post on a specified publish date via link?
- Exclude Posts from a Widget
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- Query String for the WP_QUERY parameters
- $wpdb query for price in custom field value
- Filter posts/pages by user_role array
- Run an update query in a function
- Multiple terms not working on taxonomy
- Sorting of coupons in the right way
- excludeCat function reverses order of blog posts
- Run search query again without pagination gives no results?
- Where can I find the SQL to get the most used information by wordpress database?
- WooCommerce Total # orders [closed]
- ‘Active lotteries’ only custom query for woocommerce lottery plugin and elementor
- How to show sticky posts on all pages of the pagination, not just the first page?