Displaying Custom Taxonomies From Multiple Custom Post Types

I have multiple custom post types and each of them has multiples categories. I’m trying this code to display certain categories from all of the custom post types + regular post.

<?php query_posts( array(
 'post_type' => array( 'post', 'miss_behave','emily_davies', 'gemma_patel', 'poppy_smythe' ),
 'tax_query' => array(
    'relation' => 'AND',
    array(
        'taxonomy' => 'category',
        'field' => 'term_id',
        'terms' => 4
    ),
    array(
        'taxonomy' => 'miss_behave_category',
        'field' => 'term_id',
        'terms' => 141
    ),
    array(
        'taxonomy' => 'emily_category',
        'field' => 'term_id',
        'terms' => 142
    ),
    array(
        'taxonomy' => 'gemma_category',
        'field' => 'term_id',
        'terms' => 143
    ),
    array(
        'taxonomy' => 'poppy_category',
        'field' => 'term_id',
        'terms' => 144
    )


),
 'showposts' => 4)
 ); if (have_posts()) : ?>

Which then the page doesn’t show anything. The page shows something only if I query the default post only.

Read More

Please help!

Related posts

Leave a Reply

1 comment

  1. I figured it out. Setting ‘relation’ to ‘OR’ is important.

    <?php $myquery['tax_query'] = array(
    'relation' => 'OR',
    array(
        'taxonomy' => 'category',
        'terms' => array('home-slides'),
        'field' => 'slug',
    ),
    array(
        'taxonomy' => 'miss_behave_category',
        'terms' => array('home-slides-1'),
        'field' => 'slug',
    ),
    array(
        'taxonomy' => 'emily_category',
        'terms' => array('home-slides-2'),
        'field' => 'slug',
    ),
    );
    query_posts($myquery);
     ?>