Skip Navigation

[Resolved] Nested Views not filtering by Parent Taxonomy

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

Problem: I have two custom post types in a one-to-many relationship. Each custom post type has a different custom taxonomy. On the parent post page, I would like to display a list of child posts filtered by taxonomy term. The terms in the two taxonomies are identical, but the taxonomies are different.

Solution: Create a View of the child post type, filtered by the taxonomy applied to the child post type. Use a shortcode attribute to set the term slug filter. Place the View in the single parent post template, and use the shortcode attribute to pass in the parent post's term slugs using the wpv-post-taxonomy shortcode:

[wpv-view name="Your SubGroup View Name" wpv-subgroup="[wpv-post-taxonomy type='group-taxonomy-slug' format='slug' separator=',']"] 

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy

This support ticket is created 5 years, 9 months 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 2 replies, has 2 voices.

Last updated by tech-opsE 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1236701

I have two custom post types with their own taxonomies:

1) Custom Post Type: Group
Taxonomy: Group Taxonomy
2) Custom Post Type: Sub-Group
Taxonomy: Sub-Group Taxonomy

I want to create a nested view that will display Posts from Sub-Group based on what is selected from the Taxonomy "Group Taxonomy".

For Example, if I navigate to a page of "Group" that has a selected Taxonomy of "GroupA", then it should list all of the 'Sub-Group" posts that share this same taxonomy value.

I have tried the following and it is not working as expected:

1) Create 2 Views, a parent and a child view.
2) The Parent view will contain the child view.
3) The Parent View contains a filter of Taxonomy Filter -> "Group Taxonomy" -> "Set by the page where this view is shown".
4) The Child View contains a filter of Taxonomy Filter -> "Sub-Group Taxonomy" -> "Set by the parent Taxonomy View".

I have defined both Taxonomies with the same values:

Taxonomy : Group Taxonomy
Values: GroupA, GroupB, GroupC, GroupD, GroupE

Taxonomy: Sub-Group Taxonomy
Values: GroupA, GroupB, GroupC, GroupD, GroupE

Currently, no results are being displayed within this nested view. What should happen is the following:

1) Go to a custom post type of "Group".
2) This custom post type has "GroupA" selected within their taxonomy of "Group".
3) This custom post type should now list all of the custom post types of "Sub-Group" that also have "GroupA" selected for their taxonomy of "Child Taxonomy".

Any help is greatly appreciated!

#1236705
Screen Shot 2019-04-28 at 1.54.17 PM.png

Hi, you can do this with just one View - a View of SubGroup posts. Configure a SubGroup taxonomy Query Filter to use a shortcode attribute like wpv-subgroup, and respond to a term slug (see the attachment). Then place the View in your single Group post template. In the shortcode, use the wpv-subgroup attribute to pass in the slugs of any Group terms associated with the Group post, using the wpv-post-taxonomy shortcode. Those slugs will be passed into the SubGroup Taxonomy filter of the SubGroup View, and only matching SubGroup posts will be displayed. The shortcode structure will look something like this:

[wpv-view name="Your SubGroup View Name" wpv-subgroup="[wpv-post-taxonomy type='group-taxonomy-slug' format='slug' separator=',']"] 

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/

More about the post taxonomy shortcode here:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy

#1236711

This is exactly what I wanted and it is now working perfectly. Thank you so much! I hope this helps out anyone else who wants to display this type of group listing.