WordPress.org

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
Querying taxonomy and cpt-onomy in one query (2 posts)

  1. redsentence
    Member
    Posted 1 year ago #

    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/

  2. sunriseweb
    Member
    Posted 1 year ago #

    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',
                       )
                     )

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.