I am creating a WordPress query and I want to display all posts that are either in a specific category OR match an ACF meta query. I know I can query all the posts by category like this:
$queryArgs = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'cat' => 5
)
But the problem is I also want to query additional posts by an Advanced Custom Fields value and none of those posts exist within category 5
. Obviously the following won’t work since it’s still searching only in that specific category:
$queryArgs = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'cat' => 5
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'size',
'value' => 'large',
'compare' => '='
)
)
);
So my question is, instead of displaying all posts from category 5
using ‘cat’ in the query arguments, is it possible to move the cat
argument into the meta query so that I can make the relation an OR
?