• Hi.

    This is what I want to do :
    Imagine that I have these categories for my posts.

    Color
    – Red
    – Black
    – White

    Year
    – 2011
    – 2012
    – 2013

    Now I want to select “red and white” posts that are 2012.

    Logically all the post that re “red and 2012” or “white and 2012”.

    I tried cat , category__and and category__in , but no lock

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think you can use a tax_query to do that. I have not tested this, but it should be close:

    $args = array(
    	'post_type' => 'post',
    	'tax_query' => array(
    		'relation' => 'AND',
    		array(
    			'taxonomy' => 'category',
    			'field' => 'slug',
    			'terms' => array( 'red', 'white' )
    		),
    		array(
    			'taxonomy' => 'category',
    			'field' => 'slug',
    			'terms' => array( '2012' ),
    			'operator' => 'IN'
    		)
    	)
    );
    $query = new WP_Query( $args );
    Thread Starter Farzanmc

    (@farzanmc)

    Thank you vtxyzzy.
    So far so good. The first test returned the right results. Although I didn’t use ‘operator’ => ‘IN’ , but no difference.
    I’ll try to expand my code with different options and then put it here for anyone who has the same problem.
    Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query Posts Argument Selection’ is closed to new replies.