0

What Im looking to do is look if on one page out put posts that have 2 cats selected (they must have both selected to be shown, not just one cat)

if (is_page(15) || $post->post_parent=="15") {
  $option1 = '11, 4';
  $option2 = '11, 7';}

  <?php $my_query_args = array( 
      'posts_per_page' => 10,
      'meta_key' => 'price',    
      'meta_value_num' => '',   
      'orderby'  => 'meta_value_num', 
      'order' => 'asc', 
      'tax_query' => array(
          array( 
            'taxonomy' => 'category',  
            'field' => 'id', 
            'terms' => array( $inventory_home ),
            'operator' => 'AND'
          ) 
      )
  );
$my_query = new WP_Query( $my_query_args );?>
  • 1
    Your code is rather unclear. What are $option1 and $option2? What is $inventory_home? – vancoder Mar 26 '13 at 20:59
1

Your query has some odd elements like 'meta_value_num' => '', but it sounds to me like what you want is exactly what category__and does.

$my_query_args = array( 
     'posts_per_page' => 10,
     'meta_key' => 'price',    
     'category__and' => array($catid1,$catid2),   
     'orderby'  => 'meta_value_num', 
     'order' => 'asc'
);

Side note: your price meta key will not order in a way that you think is correct unless the associated values actually are numbers.

  • I will try that.. but does that require them to have BOTH categories in order to show? – jeremy rice Mar 26 '13 at 23:24
  • Yes, category__and "shows posts that are in both categories". – s_ha_dum Mar 26 '13 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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