Skip Navigation

[Resolved] Group Relationship Results by Relationship Taxonomy

This support ticket is created 4 years, 3 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.

Our next available supporter will start replying to tickets in about 7.17 hours from now. Thank you for your understanding.

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 aprilA 4 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1731339
Screen Shot 2020-08-07 at 1.25.01 PM.png

So I currently have a many-to-many relationship between 2 post types. I am currently wanting to pull all results for a relationship, but then group the results into categories based upon the taxonomy of the post type. Each group would then have a Title above the results.

Is there a similar example that we can see?
https://toolset.com/forums/topic/divide-search-results-by-category-taxonomy/
I feel like this is similar to what I am trying to do, but not exactly the same.

What is the link to your site?
hidden link

The attached screenshot is an example of what I am wanting to do. The taxonomy of the products is selective, non, pre & post.

#1732429

Hi, normally you would create a View of taxonomy terms and insert a nested View of posts filtered by post relationship. If there are many taxonomy terms I would recommend this approach, but if there are only 4 terms then that might be over-complicating things. I see from your ticket history you have been using Views in the past so I'm assuming you are continuing to build using the classic editor, please let me know if that is not the case. I also assume this View will be displayed in the template for one of the post types in the many-to-many relationship, in this case it looks like a Weed post. So I would create one View of the Product post type and add a post relationship filter where the related Weed post is set by the post or page where the View is shown. I would also add a taxonomy filter for the selective/non/pre/post taxonomy where the term is set by one shortcode attribute like wpvtaxslug (this is arbitrary). In the loop of this View, I would display the Product post title with a link.

Next, you will insert the group title text manually, followed by the View shortcode, once for each term in the taxonomy. Add the corresponding term's slug to your View's taxonomy filter shortcode attribute like this, where selective represents the slug of the Selective term and wpvweedtaxslug represents the shortcode attribute set in your View's Query Filter:

Selective<br />
[wpv-view name="your-product-view-slug" wpvweedtaxslug="selective"]

Repeat that structure for each term.

Let me know if I've misunderstood what you want to accomplish, if you'd prefer a more dynamic approach to support more than these 4 terms, or if you need more information in general.

#1733105
Screen Shot 2020-08-10 at 7.52.46 AM.png

Thanks for the reply Christian. I believe you pretty much described what I have already setup. Below is the screenshots of my current view/setup. The reason I was trying to make it more dynamic, is that I wanted each group to automatically create its own Header of "Weed Type" for each taxonomy and then if there wasn't a product tied to the weed for the group, the group header wouldn't appear.

Here is my current setup. The issue with this current method is that its not able to conditionally display the headers of each taxonomy as I am "hard coding" the Headers above the view shortcode.

Loop Editor

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-post-body view_template="loop-item-in-test-products-to-weeds"]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Templates in this View

<a href='[types field="product-url" output="raw"][/types]' ><p>[types field="product-name"][/types]</p></a>

Then when I embed the view in my weed template page I am calling the view like this:

Selective
[wpv-view name="products-to-weeds" wpvproducttype="selective"]

Non-Selective
[wpv-view name="products-to-weeds" wpvproducttype="non-selective"]

Pre-Emergent
[wpv-view name="products-to-weeds" wpvproducttype="pre-emergent"]

Post-Emergent
[wpv-view name="products-to-weeds" wpvproducttype="post-emergent"]
#1733425

My issue is resolved now. Thank you!

I was making it more difficult trying to use conditionals when in reality I could have been using this method:
https://toolset.com/forums/topic/conditional-statements-based-on-view-shortcode-attribute-or-not-empty/

My final code ended up being pretty simple.
My shortcode:

[wpv-view name="products-to-weeds" wpvproducttype="selective" heading="Selective"]
[wpv-view name="products-to-weeds" wpvproducttype="non-selective" heading="Non-Selective"]
[wpv-view name="products-to-weeds" wpvproducttype="pre-emergent" heading="Pre-Emergent"]
[wpv-view name="products-to-weeds" wpvproducttype="post-emergent" heading="Post-Emergent"]

My Loop

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
<strong>[wpv-attribute name="heading"]</strong>
	<wpv-loop>
		[wpv-post-body view_template="loop-item-in-test-products-to-weeds"]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
	[/wpv-no-items-found]
[wpv-layout-end]