Hi,
I have CTP with two taxonomies assigned:
TaxA with terms TermAA, TermAB, TermAC
TaxB with terms TermBA, TermBB, TermBC
I want to display CTP the following way:
TermAA
TermBA
Posts
TermBB
Posts
TermBC
Posts
TermAB
TermBA
Posts
TermBB
Posts
TermBC
Posts
TermAC
TermBA
Posts
TermBB
Posts
TermBC
Posts
I am trying to nest one taxonomy into another, but apparently I do it incorrectly. May I ask for some hints?
Hi, the trick here is how to pass the taxonomy terms into the View's query filter. I would start out by creating a View of taxonomy A, and include the term title in the loop. Then I would create a View of taxonomy B, and include the term title in the loop. Now insert View 2 in the loop of View 1. Place View 1 somewhere on the site. You should see the nested terms appear, but no posts.
Next, create a View of CPT posts (will call it View 3 here) and open up the Query Filter panel. Add two taxonomy term filters, one for taxonomy A and another for taxonomy B. Configure the filters so that the term slug is set by one shortcode attribute, and choose different attributes for taxonomy A and taxonomy B. Take a look at the screenshot here for more details about that.
Now you need to pass the term slugs from taxonomy A and taxonomy B into the View of CPT posts. Place the View 3 shortcode in the loop of View 2, and add the Tax B slug in the Tax B attribute you specified in the Query filter. In my example, the View 3 shortcode would now look like this:
[wpv-view name="my-view-3-slug" wpvbooktax="[wpv-taxonomy-slug]"]
Next you need a way to pass the taxonomy slug from Tax A into the View of Tax B, so you can place that slug in the View shortcode as well. So you'll have to go back to View 1 and find the shortcode where you inserted View 2. Now add the Tax A slug to that shortcode using any arbitrary shortcode attribute:
[wpv-view name="my-view-2-slug" mytaxa="[wpv-taxonomy-slug]"]
So now you have access to the mytaxa shortcode attribute in View 2, and you can add that value to the View 3 shortcode attribute using the wpv-attribute shortcode like so:
[wpv-view name="my-view-3-slug" wpvbooktax="[wpv-taxonomy-slug]" wpvflattax="[wpv-attribute name='mytaxa']"]
This technique is called passing arguments to Views, and is explained in greater detail here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/
Hi Christian,
now I have a better understanding of how arguments passing works. Thanks, your guide works for me.
I would need to tune up one thing: TaxB above should display only those term titles which have posts assigned. Now all TaxB term titles are showing even though they are empty. TaxA shows only nonempty term titles.
The best way to do this is to move the TaxB term title inside the post View, inside the wpv-items-found but just before the wpv-loop tag, so it only appears if there are results. You probably must pass that term title as a separate argument into the post View.
My issue is resolved now. Thank you!