Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have searched in the stackexchange site for an answer for this question. However, I did not find any posts can help me solve the following problem:

I have 2 custom taxonomies named tax1 and tax2

I want to create a args for WP_Query which must meet the following conditions: - The posts must be in both tax2 and tax2 - The posts are in the custom post_type posttype1

I have tried to create the following args to get the posts but it did not work as I expected:

$query_args = array(
        'post_type' => 'posttype1',
        'ignore_sticky_posts' => 1,
        'posts_per_page' => 10,
        'offset' => 0,
        'orderby' => date,
        'order' => ASC,
        'post__not_in' => array( get_the_ID() ),
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'tax1',
                'field' => 'id',
                'terms' => array ( ... ), // an array of term
                'operator' => 'IN'
            ),
            array(
                'taxonomy' => 'tax2',
                'field' => 'id',
                'terms' => array ( ... ), // an array of term
                'operator' => 'IN'
            )
        )
    );

Could anyone help me to solve this problem please?

Thanks

share|improve this question
    
Please elaborate: "but it did not work as I expected". –  kaiser Aug 27 '12 at 21:32
    
I mean this returned nothing –  iLoveWP2012 Aug 27 '12 at 22:56
    
Please turn on all WordPress and PHP Debug levels. Then install the Debug Bar and it's extensions. You'll be able to show the complete query that doesn't work. Maybe there's a fix. –  kaiser Aug 28 '12 at 1:09
    
OK. The answer for why the above code did not work was my false. I defined wrong taxonomy slug :(. Thanks for your help kaiser. –  iLoveWP2012 Aug 28 '12 at 1:23
    
Hmm. The above code worked OK when I selected two specific taxonomy term ids. However, when I selected "All Tax1" or/and "All Tax2" (I mean the term id is 0), the above code did not work. Do you have any idea? –  iLoveWP2012 Aug 28 '12 at 1:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.