Support » Plugins » limit multiple categories tax_query by tag not working

  • Resolved shagen

    (@shagen)


    Displaying posts that are tagged with ‘resource’. The following code is working great…

    $querystring = array(
    		'cat' => 'category__in => array('.$cat.','.$topic.')',
    		'posts_per_page' => -1,
    		'tag' => 'resource',
    		'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
    	);

    However this code is working but not honoring the ‘resource’ tag…

    $pagesorter['tax_query'] = array(
    		'tag' => 'resource',
    		'posts_per_page' => -1,
    		array(
    			'taxonomy' => 'category',
    			'terms' => $cat,
    			'field' => 'id',
    		),
    		array(
    			'taxonomy' => 'category',
    			'terms' => $topic,
    			'field' => 'id',
    		),
    	);

    How do I get the above piece of code to honor the posts that are tagged ‘resource’? I am sure I have something out of order or wrong. I have tried putting it within each array with no luck as follows.

    $pagesorter['tax_query'] = array(
    		'posts_per_page' => -1,
    		array(
    			'taxonomy' => 'category',
    			'terms' => $cat,
    			'field' => 'id',
    			'tag' => 'resource',
    		),
    		array(
    			'taxonomy' => 'category',
    			'terms' => $topic,
    			'field' => 'id',
    			'tag' => 'resource',
    		),
    	);

    Any thoughts, ideas and help would be greatly appreciated! Thanks for your time everyone!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can’t put ‘tag’ and ‘posts_per_page’ directly in ‘tax_query’.

    If you put them in the outer query vars array, you will get the expected results:

    $pagesorter = array(
    	'posts_per_page' => -1,
    	'tag' => 'resource',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category',
    			'terms' => array( $cat, $topic ),
    			'field' => 'id',
    			'operator' => 'AND'
    		),
    	)
    );

    Also, as you can see, you can put both category ids in one inner tax query.

    That is like super hero stuff and it works perfectly! Thanks for the time.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘limit multiple categories tax_query by tag not working’ is closed to new replies.