• Resolved hendri salim

    (@hendri-salim)


    Hi,

    I’m sure this is just operator problem but i just cant get it working. What i’m trying to do is to query post type a with category b, and post type c with category d and show it in one result. Thanks in advance

    Here is my code:

    query_posts(array( array(
    					'post_type' => array('post'),
    
    					'tax_query' => array(
    							array(
    							 'taxonomy' => ('category'),
    							 'terms' => array('android'),
    							 'field' => 'slug')
    							),
    
    					'paged' => $paged
    
    					)),
    						array(
    					'post_type' => array('reviews'),
    
    					'tax_query' => array(
    							array(
    							 'taxonomy' => ('review_category'),
    							 'terms' => array('android'),
    							 'field' => 'slug')
    							),
    
    					'paged' => $paged
    					    ));
Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    You are passing two parameters as in query_posts($array1,$array2) instead of a single array parameter containing sub arrays as in query_posts($array0)

    In other words, there should be one closing parenthesis after the first 'paged' => $paged and three after the last.

    …I think. Easy to get lost in array levels!

    Thread Starter hendri salim

    (@hendri-salim)

    Thanks but still not working

    [ Please do not bump, it’s not permitted here. ]

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this [untested]:

    $args = array(
    	'post_type' => array('post','reviews'),
    	'paged' => $paged,
    	'tax_query' => array(
    	  array(
    	    'taxonomy' => 'category',
    	    'terms' => 'android',
    	    'field' => 'slug'
    	  ),
    	  array(
    	    'taxonomy' => 'review_category',
    	    'terms' => 'android',
    	    'field' => 'slug'
    	  ),
    	)
    );
    query_posts($args);

    Thread Starter hendri salim

    (@hendri-salim)

    Hi,

    Sorry but is still not working ( i got blank result). I got the idea but the operation syntax is killing me. Thanks

    Regards

    Moderator keesiemeijer

    (@keesiemeijer)

    I just tested this and I hope this works for you:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
    	'post_type' => array('post','reviews'),
    	'paged' => $paged,
    	'tax_query' => array(
              'relation' => 'OR',
    	   array(
    	     'taxonomy' => 'category',
    	     'terms' => 'android',
    	     'field' => 'slug'
    	   ),
    	   array(
    	     'taxonomy' => 'review_category',
    	     'terms' => 'android',
    	     'field' => 'slug'
    	   ),
    	)
    );
    query_posts($args);

    Thread Starter hendri salim

    (@hendri-salim)

    Hi,

    Thanks gazilion times, works like a charm. Super! Thanks

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. Glad you got it resolved ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Query Multiple post type with multiple taxonomies’ is closed to new replies.