I was unable to create a WP_Query – I believe it is not possible to solve this using a regular WP_Query – but managed to create an SQL statement that does exactly what I want:
SELECT wp_posts.*
FROM wp_posts
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id)
WHERE 1=1
AND wp_posts.post_type="pass"
AND (wp_posts.post_status="publish")
AND (
wp_postmeta.meta_key = 'start_time'
AND (
(
mt1.meta_key = 'event'
AND CAST(mt1.meta_value AS CHAR) = '10011'
)
OR (
mt1.meta_key = 'meeting_type'
AND CAST(mt1.meta_value AS CHAR) != 'other'
)
)
)
GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value ASC
Related Posts:
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Sorting: custom query with orderby meta_value_num THEN by title
- Custom WP_Query order by post_meta and (author) user_meta
- What is an efficient way to query based on post_meta?
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Advanced WP Query hogs the SQL server
- Order WP Query posts by custom order calculated from post meta values
- Meta query with order by another custom field
- Order Posts by meta value AND published date
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- pre_get_posts order by not working
- Optional Meta Query
- How to orderby multiple meta fields if some fields are empty
- Order by summing multiple values
- Changing sort order for presentation by Jetpack infinite scroll
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- meta_value_num not ordering all items
- How to filter a query by multiple meta keys and order by other meta keys
- Debugging wp_query orderby for taxonomy
- Advanced WP_Query with meta_query, orderby?
- WP_Query: apply an SQL function to meta fileld value
- Randomly select one of last 3 posts
- Sort posts using multiple custom fields and menu_order in single query?
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- WP Query – grouping posts by same meta key, adding together values from another key
- WordPress Query custom ordering by temporary variable
- Meta query orderby meta_value_num sorting by role first
- WP_User_Query Orderby Not Working
- Sorting with meta_query and multiple, optional meta keys
- WP Query. Ordering posts by another post types meta
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- wp_query sorting – one specific meta_key value at last and then sort by create date
- Best way to Order Post in Home without a plugin
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- Using orderby with 2 meta keys
- Sorting: custom query with orderby meta_value_num THEN by title
- orderby in WP_query doesn’t works
- WP_Query() not working as expected
- Custom Meta Query doesn’t work the same on two site
- How to sort store location by specific category order in WP store locations
- Search filter between promo and exact price
- meta_query with meta values as serialize arrays
- ElasticPress is (aparently) messing with my search filters
- 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
- Woocommerce Get Orders By Meta Value
- WP_Query for a taxonomy value OR a custom post type meta field
- Meta query ignores multiple values of the key
- meta_query is overriding default search
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Trouble with serialized metadata
- Multiple WP_Query args combinations according to post type
- Custom WP Query order function possible?
- WordPress Meta Query Null Values Order
- Multiple meta_query not returning rows
- WP_Query multiple value not working
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- meta_query order by date present -> future then show null
- show most viewed post
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- Custom order of posts in wp_query and different taxonomies
- Query for current post
- WP_Query random ordering not working since 5.4
- What is the equivalent WP_Query of a SQL Query?
- Check for not NULL not working in meta query
- Custom query to retrieve oldest post and retrieve others with date interval
- Comparing Meta Field date in WPQuery using Meta_Query?
- Custom order revolution sliders post base slides as inserted in Specific Posts List field
- Get unique post by meta value using wp_query
- Why can my filter query SOME metadata but not other metadata?
- Getting posts by custom field value
- How to create better WP_Query to look for date time which is anywhere between two meta values?
- Order by value of Custom Field using url string
- Order posts by tags count?
- Query against multiple locations within single custom post type post
- Order by meta date with a thousanth of a second defaults to post order
- Translating WP query into to SQL query
- WP Query with meta queries
- Unusual high query of user meta data
- Order Element By Custom Field in WordPress
- Very slow query generated getting meta data from posts
- WP_Query on custom key and value
- WordPress Query optimaization for slow query
- WP_Query, ACF field and array
- Get posts having meta value between two numbers
- wordpress multiple meta value query is not working
- Strange results from WP_Query
- Query Order By Number Variable From API
- How to get_comments() ordered by date and parent?
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- Pre get posts sort by meta key returns no results if meta key does not exist
- Order 2 meta_queries differently in WP_Query?
- Order by Date Custom Field
- How to filter on placeholder image
- Filtering WP_Query based on wp_postmeta keys values
- meta_query compare > not working
- Filtering posts for unique titles, only the most recent
- Complex Meta Query
- meta_query with relation = AND not working as expected when combining EQUALS with NOT EQUALS