Skip Navigation

[Resolved] Nested View of Related Posts, sorted by Taxonomies of connected Posts

This support ticket is created 4 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Minesh 4 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1533549

Hello,

I’m hoping you can help with creating a nested views layout that displays all related posts (connected by many-to-many relationship), sorted by the taxonomies of the connected posts. The taxonomy would become the parent view. Here’s some notes about my setup:

———

Details about our Custom Post Type & Taxonomy Setup:
Services Post Type: For services we offer (i.e.: Spray Foam Insulation, Fiberglass Batts, Rockwool Insulation, etc)
Services Taxonomy - Services Categories: (i.e.: Insulation Services, Other Services, Roofing Services)
Services Taxonomy - Job Types: (i.e.: Residential, Commercial, Public Works, etc.)

— Example Uses on the site —
Example of Taxonomy Archive for “Services Category Insulation”: hidden link
Views used are Taxonomy View based on Page with Nested view of each CPT that’s connected
Works Perfectly!

Example of Taxonomy Archive for “Job Types Residential”: hidden link
View is a Taxonomy Archive with a Nested view of each CPT that’s connected
Works Perfectly!

— What I Need —
I have created a new CPT called “Office Locations”, and set a many-to-many Post Relationship with the “Services” Custom Post Type. One of my “Office Locations” posts is for our “Phoenix” Office, link here: hidden link

On this Phoenix page, I am listing all the services performed at this office, which are the Services Posts that are included in the many-to-many relationship with “Office Locations”. For this example, there are three (3) services connected: Closed Cell Foam Insulation, TPO Insulation & Open Cell Foam Insulation.

I want to display the “Services” organized by the Services Category Taxonomy, so the results look just like how they do on the Job-Type Taxonomy archive here: hidden link

I do not see a way to create a nested view of the Related Post Taxonomies (Parent View) connected to the page where the view is displayed, then display a nested (child view) of each of the posts. The expected result for this Phoenix page would be:

[Taxonomy - “Services Category”: Insulation]
[Services Post: “Open Cell Foam Insulation”]
[Services Post: “Closed Cell Foam Insulation”]

[Taxonomy - “Services Category”: Roofing]
[Services Post: “TPO Roofing”]

Please advise if this is possible! Thank you!

#1534923

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I will still require admin access details so I can review your current setup and once I review that I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1552085

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the following view's filter code to "Custom Code" section of Toolset to filter your taxonomy view with the current taxonomy term archive Id:
=> hidden link

add_filter( 'wpv_filter_taxonomy_query', 'func_prefix_modify_tax_query', 999, 3 );
 function func_prefix_modify_tax_query( $tax_query_settings, $view_settings, $view_id ) {
  if($view_id == 1631){
      
     $tax_query_settings['include'] =  get_queried_object()->term_id;
      
    
  }
  return $tax_query_settings;
}

I can see when I load the taxonomy archive for the term "insulation" - it now displays only that term posts.
=> hidden link

#1553085

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please confirm it works as expected at your end.

#1556219

Thank you! It appears to be working. What was the need for the custom code snippet? It was working just fine for a year and a half? Only thing I did differently is make the Service Categories Taxonomy linked to Office Locations?

#1556985

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that the solution I shared works for you.

What was the need for the custom code snippet? It was working just fine for a year and a half? Only thing I did differently is make the Service Categories Taxonomy linked to Office Locations?
==>
The code I've added is to include the current term taxonomy term ID to your taxonomy view so that it should only fetch that term ID posts. Maybe it's due to the taxonomy view added to your archive page. But I'm happy that the code I shared lead you to resolve your issue.