Quantcast
Channel: Question and Answer » meta-query
Viewing all articles
Browse latest Browse all 36

Query Multiple Post types each with own meta query

$
0
0

I have 2 post types: lets say products and product_variations. I’d like to be able to modify the query via pre_get_posts to get all product with meta_keys "_visible" = "true" and "_available" = "true" AND all product_variations with meta_key "_featured" = "true".

The product_variations don’t have the meta_keys "_visible"/"_available" and vice versa, so a straight up AND meta_query returns no results. OR relation isn’t quite right either as two fields are AND related for one post type then OR related to the other post type.

To make that slightly more visual because I just realized how complex it is to write out:

**product**        
_visible = true      
_available = true

**product_variation**      
_featured = true

Is this possible via query args?
Is this possible via posts_where?
Do I need to run a separate query and then somehow merge the results?


Viewing all articles
Browse latest Browse all 36

Trending Articles