1

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.

Please help!

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.