I am trying to query posts according to their post format. Currently, I have the video, gallery, and standard post formats on my site. It’s quite easy to query these post formats individually. However, I have a combination of tax queries of 10 posts that are standard and video post format, my query fails.
Here’s the code I have right now:
$args = array(
'post_status' => 'publish',
'orderby' => 'date',
'posts_per_page' => 10,
'relation' => 'OR',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'operator' => 'IN',
'terms' => array( 'post-format-video' )
),
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-video', 'post-format-gallery' ),
'operator' => 'NOT IN'
)
)
);
$query = new WP_Query( $args );
2
Answers
I think, you should put the
'relation' => 'OR',
into the'tax_query'
-Array.You are adding
'relation' => 'OR'
in the wrong place. it should be inside thetax_query
array. check the below code.USEFUL LINKS