Support

Account

Home Forums Reply To:

  • I am building a products page with a selectable options sidebar. I have 2 custom post types for this ‘products’ for the main products and ‘options’ for the extra selectable options they can request for each product.

    The ‘options’ post type also uses the ‘option-categories’ taxonomy to categories the available options.

    Inside the New Post for ‘products’ I’ve added the ‘taxonomy’ (opt_tax) and ‘relationship’ (prod_options) field. The idea being that my client and select which options he wants to added to the sidebar.

    I wanted to do this with just the ‘relationship’ field but that doesn’t seem to be possible as it doesn’t seem to relate the posts to the taxonomies.

    What I can’t do at the moment is just get the ‘option-categories’ taxonomies to display according to the ones selected in the taxonomy field (opt_tax). At the moment this is my current code below. The ‘relationship’ part works as I’d like it to, I need to display the relevant taxonomies either with the relationship field or the taxonomy field.

    Thanks for any help on this.

     <?php
    
          $taxoIds = get_field('opt_tax');
    
          $tax = 'option-categories';
    
          $optArgs = array(
            'taxonomy'   => $tax,
          );
    
          $options_cat = get_terms($optArgs);
          foreach ($options_cat as $opt_parent) {
    
            $optID = $opt_parent->term_id;
    
             echo $opt_parent->name;
    
              $optIds = get_field('prod_options', false, false);
    
              $prodOpts = array(
                'post_type'    => 'options',
                'orderby'      => 'name',
                'order'        => 'DESC',
                'post__in'			=> $optIds,
                'tax_query'    => array(
                  array(
                    'taxonomy' => $tax,
                    'field'    => 'term_id',
                    'terms'    => $optID,
                  ),
                )
              );
    
              $wc_query = new WP_Query($prodOpts);
    
              if ($wc_query->have_posts()){ ?>
                <div class="card-body">
                  <ul>
                    <?php
                   
                    while ($wc_query->have_posts()){
                     
                      $wc_query->the_post();
    
                    ?>
                        <li>
                          <?php the_title(); ?>
                        </li>
    
                    <?php } ?>
                  </ul>
                </div>
              <?php wp_reset_postdata(); } } ?>