How do I loop through FAQ items by product and FAQ category within a Tabs element?

Hi there,

I am trying to loop through FAQ custom post types that have both a “product_category” and a FAQ category (“faq-kategorie”). The tabs on top shall contain the products, whilst the individual panels of the tabs elements contain the respective FAQ categories in the left column (the terms) and a list of the questions in the right column. Sort of a nested loop, I guess.

Clicking on a category shall display the respective questions pertaining to both the product and the FAQ category in the right column.

How do I achieve that? I tried both an Archive and Page.

I already have single tabs containing the product taxonomies but I cannot populate the panels .

Thank you!

Cheers,
Jens

Hello @Paritor,

Thanks for writing in!

You will have to nest a Looper Provider All Terms. For example:

Looper Provider All Terms (product_category)
   Looper Consumer
         Display the Tabs (for each product category) 

         Looper Provider All Terms (faq-kategorie)
               Looper Consumer
                     Display Terms (each faq-kategorie)

The product category and the faq-kategorie doesn’t seem to have a connection. So, you will have a multiple taxonomy in your argument like this:

$args = array(
    'post_type' => 'faq',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'faq-kategorie',
            'field'    => 'slug',
            'terms'    => 'wordpress',
        ),
        array(
            'taxonomy' => 'product_category',
            'field'    => 'slug',
            'terms'    => 'plugins',
        ),
    ),
);

You can use “AND” or “OR” relationship.

By running the var_dump( http_build_query( $query ) );, this can give us a query string: post_type=faq&tax_query%5Brelation%5D=AND&tax_query%5B0%5D%5Btaxonomy%5D=faq-kategorie&tax_query%5B0%5D%5Bfield%5D=slug&tax_query%5B0%5D%5Bterms%5D=wordpress&tax_query%5B1%5D%5Btaxonomy%5D=product_category&tax_query%5B1%5D%5Bfield%5D=slug&tax_query%5B1%5D%5Bterms%5D=plugins

You can replace wordpress with {{dc:term:slug depth=1}} and plugins with {{dc:term:slug depth=0}}.

Hope this makes sense.