Skip Navigation

[Resolved] Limit term page navigation to within the 2nd level term

This thread is resolved. Here is a description of the problem and solution.

Problem: I am using a View of taxonomy terms ordered by custom field value to show links to the next and previous term archives. I would like to filter those Views by term grandparent, so that only terms in the same grandparent are included in the results.

Solution: There is no term grandparent filter, so you can use another custom field in the Class Parts taxonomy. For each class, use a different field value. So for Knitting Superstar and all its descendant terms, use "knitting-superstar". For Fearless Knitter and all its descendant terms, use "fearless-knitter", etc. Then add a filter to the Next and Previous Views that filters by this custom field, set by a shortcode attribute. In the View shortcodes for the Next and Previous View, use a Types termmeta shortcode to insert the current term archive's custom field value in a shortcode attribute.

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

This support ticket is created 6 years, 1 month ago. 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.

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)

This topic contains 3 replies, has 2 voices.

Last updated by liatG 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1109549
Next chapter link points to different class.png

Hi Christian,

I am almost done setting up my membership site and posting support questions. Thank you for your help.

This is an add-on question to https://toolset.com/forums/topic/help-setting-up-term-pagination-in-term-archive-pages/.

I'm looking for a way to modify the Custom Code you gave me to limit the term pagination to just within the 2nd level term of the archive, for instance within the "Knitting Superstar" term or "Fearless Knitter" term.

Right now, having added other classes to my class-parts taxonomy, the term pagination want to skip to those other classes.
If I number the class parts 1, 2, 3, 4, for each class in the taxonomy, the Next Chapter navigation on the Fearless Knitter class points to the next chapter in the Knitting Superstar class.

If I number the class parts 1, 2, 3, 4 for the first class and 5, 6, 7, 8 for the second class, the last page of the class will have a navigation link to the first page of the next class.

I want to avoid having the navigation point to chapters in different classes. People should just be able to navigate within that class, i.e. anything that is within the 2nd level term.

In the attached screenshot I'm hovering over the "next chapter" link, and in the url preview in the bottom left you can see that it goes to a chapter in the Knitting Superstar class. But in the URL bar above you can see that I'm in the Fearless Knitter class.

Thank you!
Liat

#1110615

It looks like you need to be able to filter the Next and Previous Views by term ancestor, based on the current archive term's ancestors. Views offers a term parent filter, but no filter for term ancestor (farther back than parent, like grandparent or great-grandparent). So there are a couple of other ways to do this - a custom field, or a dynamic term ID filter.

1. Custom Field Filter: Add a custom field to the Class Parts taxonomy. For each class, use a different field value. So for Knitting Superstar and all its descendant terms, use "knitting-superstar". For Fearless Knitter and all its descendant terms, use "fearless-knitter", etc. Then add a filter to the Next and Previous Views that filters by this custom field, set by a shortcode attribute. In the View shortcodes for the Next and Previous View, use a Types termmeta shortcode to insert the current term archive's custom field value in a shortcode attribute. This will filter the View by class part. This option is probably the fastest to set up, but arguably more difficult to maintain because you must manually manage these custom field values.

2. Dynamic Term ID Filter: Add a taxonomy term filter to the Next and Previous Views. Set it up to filter by term ID using a shortcode attribute "ids". This lets you add class part term IDs to the View shortcodes, like this:

[wpv-view name="class-parts-filtered-by-part-order-next" ids="1,3,4,23,39"]

This View will only show terms whose IDs are 1, 3, 4, 23, or 39. You would need a way to make the "ids" dynamic, based on the current term archive. That will require a custom shortcode that inspects the current archive's term ancestors and returns a list of the term childrens' ids. This will be more difficult to set up, but arguably easier to maintain because you don't have to maintain a custom field value in all the terms.

Let me know which approach you would prefer and I can offer some more detailed advice.

#1110693

Hi Christian,
Thank you so much!

I am definitely ok with setting up a custom field and putting in some value for each class. I could put in "fk" for Fearless Knitter or "ks" for Knitting Superstar.

I am going to attempt this on my own. I'll be back with questions shortly.
Liat

#1110728

It worked perfectly! I was able to follow your directions and use the shortcode filters and termmeta shortcode to filter the views.

Thank you SO SO much for providing instructions I can follow.

Cheers!
Liat