• Hi! I have a CPT named Products and two taxonomies, Brands and Product Categories. My client wants to start at a Brand page, displaying the Product Categories in the particular brand, then to click through to a page with all the Products under that Brand and Product Category.

    Well, I have started this trek on the taxonomy-brands.php page and am trying to just query the product categories relevant to that brand, but for some reason, it is pulling ALL of the product categories. Any suggestions on a better way to accomplish this?

    ?php

    $slug_brands = get_query_var( ‘term’ );
    $term_brands = get_term_by( ‘slug’, $slug_brands, ‘brands’ );
    $term_id_brands = $term_brands->term_id;
    ?>
    <h1><?php echo $term_brands->name; ?></h1>
    <p><?php echo $term_brands->description; ?></p>

      <?php
      $args=array(
      ‘post_type’ => ‘products’,
      ‘parent’ => 0,
      ‘tax_query’ => array(
      array(
      ‘taxonomy’ => ‘brands’,
      ‘parent’ => $term_id_brands,
      ‘terms’ => $term_brands,
      ‘field’ => ‘slug’
      )
      )
      );
      $terms = get_terms( ‘product_categories’);
      foreach($terms as $term) {
      echo ‘

    • ‘.$term->name.’
    • ‘;
      }?>

    Thank you!

  • The topic ‘Navigate to a CPT through two taxonomy queries??’ is closed to new replies.