Skip Navigation

[Gelöst] Nesting taxonomies

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: I have two custom taxonomies, TaxA and TaxB. I would like to create a filtered list of posts organized by taxonomy term in a nested format where TaxA is the top-level structure, with all TaxB terms nested inside each TaxA term, and filtered posts displayed beneath TaxB terms.

Solution: Use a series of nested Views filtered by shortcode attributes.

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created vor 5 Jahren. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von PiotrO586 vor 5 Jahren.

Assistiert von: Christian Cox.

Author
Artikel
#1366681

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?

#1366807
Screen Shot 2019-10-22 at 2.44.20 PM.png

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/

#1367571

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.

#1367803

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.

#1368615

My issue is resolved now. Thank you!