Search code examples
wordpresstaxonomy-termspost-format

How to query Standard and Video Post Format in WordPress?


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 );

Solution

  • I think, you should put the 'relation' => 'OR', into the 'tax_query'-Array.