Skip Navigation

[Resolved] Group related items by custom taxomy terms

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 0 replies, has 1 voice.

Last updated by Minesh 1 day, 4 hours ago.

Assisted by: Minesh.

Author
Posts
#2794305

SD
3.png
2.png
1.png

Hello there, i have two CTPs "menu-item" and "location" with many to many relationship. Menu item has a custom taxonomy of "nomad-menu-category" with multiple terms.

I want to create a view so when viewing a location to retrieve all the menu-item that are related/connected to the location and grouped by "nomad-menu-category" terms.

I managed to do this by following this: https://toolset.com/2015/07/how-to-group-posts-by-category/

My issue though is that whatever i try(i tried sever conditions) it displays all the terms even if they don't have items related to that location, if a terms doesn't have items associated with that location i want to hide it.

for example in the below screenshot , "Platters" is a term it has menu items just not any associated with the current location...i want those to be hidden.

#2794331

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL where I can see the issue and also share details what views you created and send me admin access detials.

*** 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.

#2794428

Minesh
Supporter

Languages: English (English )

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

First of all - I've created the following view that will return term IDs assigned to the related menu item posts as comma separated term IDs:
=> hidden link
Where:
I've added the Query filter for the post-relationship:

Filter by post relationship or repeatable fields group owner
Select posts in a Associated Menu Items relationship that are related to the Post where this View is shown.

Then, to the menu category list view - I've added Query Filter for taxonomy term to filter the terms by shortcode attribute "terms":
=> hidden link

Taxonomy term filter
Taxonomy term ID is set by the shortcode attribute "terms"

Then, I've created the following content template namely "ct-view-shortcode-container" and added view as given under:
=> hidden link

[wpv-view name="menu-categories-list" cached="off" terms='[wpv-view name="get-cats-belongs-related-menu-items" cached="off"]']

As you can see we are passing the view "get-cats-belongs-related-menu-items" as shortcode argument "terms" so it will only display the terms of related menu items.

Then, with your Oxygen builder template for single location post - I've remove the view which you added and added the shortcode module and added the content template "ct-view-shortcode-container" to it using the shortcode:
=> hidden link

[wpv-post-body view_template="ct-view-shortcode-container"]

You can adjust the styling as reuqired.

Please check now: hidden link

More info:
- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-body
- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-view
- https://toolset.com/documentation/legacy-features/views-plugin/filtering-views-by-taxonomy/
- https://toolset.com/documentation/legacy-features/views-plugin/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes

#2794483

SD

Hello Minesh, thank you so much for all your help.

Is it possible to explain in plain English what each thing does so i know in the future ?

For example we now have three views:
1) get-cats-belongs-related-menu-items which displays menu items based on the relationship, correct ? But what is this actually doing:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=other]
[wpv-post-taxonomy type="nomad-menu-category" format="id"],
[wpv-item index=last]
[wpv-post-taxonomy type="nomad-menu-category" format="id"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

2) menu-categories-list which displays Taxonomy -> Menu Categories with taxonomy fillter: Terms with ID set by the shortcode attribute:"terms" ....why is that ? what it does?

3) menu-items-list which again retrieves menu-itme cpt relationship and is nested inside menu-categories-list

Why do we have two views for menu items filter by relationship ?

4) And then the content template ct-view-shortcode-container which it has the shortcode [wpv-view name="menu-categories-list" cached="off" terms='[wpv-view name="get-cats-belongs-related-menu-items" cached="off"]'] what does this exaclty and wehy is it working as we want ?

Thanks in advance, I'm just asking so i know in the future and understand better what we did to achieve what wee needed.

#2794584

Minesh
Supporter

Languages: English (English )

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

1) get-cats-belongs-related-menu-items which displays menu items based on the relationship, correct ? But what is this actually doing:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=other]
[wpv-post-taxonomy type="nomad-menu-category" format="id"],
[wpv-item index=last]
[wpv-post-taxonomy type="nomad-menu-category" format="id"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
====>
Actually - "get-cats-belongs-related-menu-items" view is used to get the "nomad-menu-category" IDs attached to the Menu Items as you can see above we are retuning the category IDs using shortcode:

[wpv-post-taxonomy type="nomad-menu-category" format="id"]

2) menu-categories-list which displays Taxonomy -> Menu Categories with taxonomy fillter: Terms with ID set by the shortcode attribute:"terms" ....why is that ? what it does?
====>
That is your actual problem you created this ticket for.

As you know on your page it was displaying all categories and you want that you only want to display category where Menu Item is attached.

That is why we created the view "get-cats-belongs-related-menu-items" that will only return the category ids (term ids) as I explain above.

Now, we will use this view that will only return the term IDs where post is attached and pass this view as shortcode attribute "terms":

[wpv-view name="menu-categories-list" cached="off" terms='[wpv-view name="get-cats-belongs-related-menu-items" cached="off"]']

So, "terms" is view's shortcode argument and that will hold that ids of terms where menu item post is assigned and we filter the view "menu-categories-list" with taxonomy filter:

Taxonomy term filter
Taxonomy term ID is set by the shortcode attribute "terms"

So, view "menu-categories-list" will only display the terms where posts is assigned which we pass through the "terms" shortcode attribute.

3) menu-items-list which again retrieves menu-itme cpt relationship and is nested inside menu-categories-list
===>
That you have already - I did not make any change.

4) And then the content template ct-view-shortcode-container which it has the shortcode [wpv-view name="menu-categories-list" cached="off" terms='[wpv-view name="get-cats-belongs-related-menu-items" cached="off"]'] what does this exaclty and wehy is it working as we want ?
===>
As its a nested shortcode:

[wpv-view name="menu-categories-list" cached="off" terms='[wpv-view name="get-cats-belongs-related-menu-items" cached="off"]']

That is why I've created content template and added above shortcode withiin the content template and display the content template with your Oxygen builder. If you try to add the above nested shortcode directly to your oxygen builder it will not work as it will not get parsed/rendered correctly.

#2794601

SD

Thank you so much for all your help Minesh and your awesome explanation, have a great rest of your day...can we please remove/hide the links(oh th eprevious reply) related to the dev site? hidden link.......

Thanks again

#2794602

Minesh
Supporter

Languages: English (English )

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

I've removed the domain name and glad to help. You're welcome to mark resolve this ticket and share your experience.