• Hello!

    I have two custom post types, Products, and FAQs. FAQs has a taxonomy named faq_categories, and it also uses Products as a CPT-onomy to link the two. So on an individual product page, I need to list the FAQs by faq_category and only if they are linked to that product. Here is the code I am trying, but it is not quite working:

    <?php 
    
    $myterms = get_terms('faq_categories', 'orderby=none&hide_empty');    
    
    $prodname = get_the_title();
    
    $slug = $post->post_name;
    
    foreach ($myterms as $term) { ?>
    
             <li><a href="<?php echo $term->slug; ?>"><?php echo $term->name; ?></a>
    
             <ul>
    
    	<?php $args = array(
                 'post_type' => 'faqs',
                 'faq_categories' => $term->name,
    	    'tax_query' => array (
             array (
             'taxonomy' => 'products',
             'terms' => $slug,
             'operator' => 'IN'
              )  )
    	  );
    
              query_posts($args);
    
               if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
                <li><?php the_title(); ?></li>
    
             <?php endwhile; endif; wp_reset_query(); ?>
    
             </ul>
    
             </li> 
    
    	<?php } ?>

    Any help greatly appreciated 🙂

    https://wordpress.org/plugins/cpt-onomies/

Viewing 1 replies (of 1 total)
  • I’m having a similar problem. I had to use the method I outlined in this post – to make it work.

    You meed to do a meta_query on the Products post CPT-onomy taxonomy using the post ID. Something like:

    'meta_query' => array(
                       array(
                          'key' => '_custom_post_type_onomies_relationship',
                          'value' => array(PRODUCTS_POST_ID),
                          'compare' => 'IN',
                       )
                     )
Viewing 1 replies (of 1 total)
  • The topic ‘Querying taxonomy and cpt-onomy in one query’ is closed to new replies.