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 Args – Title or Meta Value
- Order by optional meta key?
- Whats the difference between post_limits and pre_get_posts?
- Does tax_query really beats meta_query in all situations?
- Query WooCommerce orders where meta data does not exist
- Execute a large WP_Query with many “AND” Meta_Queries?
- Query all posts where meta value is empty
- WP_Query min and max values
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Revolution Slider Orderby Two Custom Fields
- SELECT * FROM $wpdb->posts WHERE ID > 160
- Meta-value query
- Meta query field order together with post_date order causes posts without the meta field to be unordered
- pre_get_posts filter meta_query without conflicting existing meta_query
- Undefined property: WP_Query::$post
- Programmatically set ‘meta_query’ for filter
- WP_Query meta_query >= date
- Extending woocommerce admin product search
- Adding an array from a query string to a WP meta_query
- Query multiple meta values
- Query by multiple meta elements not seeming to work – wordpress is timing out
- How does one perform a sub query with different post types
- meta_compare not comparing whole integer
- Include post content of linked posts in search
- How to Create a Random List of Child Pages
- meta queries do ‘either/or’ checks
- WP Query ordering on a meta field for posts with a date in the future not ordering by datetime
- Selecting posts with a given meta value for a meta key
- Get every post with value in meta key
- get_page meta query not working, maybe a bug?
- Is it possible to add relation between meta_query and tax_query?
- Query by date from custom field
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- WP_User_Query orderby meta_val_num
- WP_Query custom order and pagination
- Comparing 2 Decimal Numbers from custom fields and displaying posts
- Order (by ASC) posts with meta_key so posts without values are last
- Search filter between promo and exact price
- WordPress Meta Query Null Values Order
- show most viewed post
- Why can my filter query SOME metadata but not other metadata?
- Getting posts by custom field value
- Order posts by tags count?
- wordpress multiple meta value query is not working
- Strange results from WP_Query
- Pre get posts sort by meta key returns no results if meta key does not exist
- meta_query with relation = AND not working as expected when combining EQUALS with NOT EQUALS
- WP Query for Multiple Post Types
- WP_Query: custom orderby (not ASC nor DESC)
- Order Posts By Custom Field That is an array of objects
- Orderby query does not work for custom fields even with meta query
- make query more simplest and in one query
- orderby in WP_QUERY – Use the order from the Dashboard
- Use not custom fields in get_posts() meta_query?
- Compare meta key separation
- WordPress Query Default Order if Meta Values Same?
- Posts2Posts, wp_query and orderby issue
- Query string form $_GET[‘value’] is not working as meta value in wp_query
- 294 Queries on Mainpage of WordPress
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- Get posts using multiple values from ACF checkbox as meta query wordpress
- WP Query returning all posts when Meta_query is null