Skip Navigation

[Resolved] Filter to show categories and then subcategories when a parent is clicked

This support ticket is created 8 years, 2 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
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+02:00)

This topic contains 22 replies, has 3 voices.

Last updated by Juan 8 years ago.

Assisted by: Juan.

Author
Posts
#371134

Hello,

As you can see on my site I have the categories outputted with a Filter (parent categories and sub-categories):

hidden link

My goal is to allow the user to first only see the top level categories like Bar, Music and Restaurant, and once they click on that it filters based on the parent category and they then also see that category’s sub-categories just below and an filter on them.

I understand I could only show Parent categories by choosing Parent is : None in the Taxonomy filter. But then I don’t know how I would make the sub-categories appear when the parent is clicked. Or if there's just a better/easier way to do this.

Tim

#371248

If you show taxonomies on a Taxonomy View you will not be able to add a parametric Search, which is actually what you would need.

But that View seems to be a Post View with a Parametric search by Taxonomy, right?

In this case it's not possible to output only parent or Child taxonomy terms in the Parametric Search.
Always all Terms will be output.
https://toolset.com/documentation/user-guides/front-page-filters/

You would need to hide them with Custom Code or a Custom WordPress DDBB Query.

I can add a feature request for you, so to add support for a Filter by Parent and Child Terms (separately)

When exactly our developers will add a new feature or not is not up-to us Supporters to determine.
Each issue reported in, whether a bug or a new feature request, is taken seriously into consideration.
It is given a high or low priority based on a number of factors.
Factors which those with the overview of all things related are in the best position to determine.
I apologize any inconvenience this may cause.

Another approach would be to create a Parent Taxonomy View, where you first display all Parent Terms.
The current Post View will be insert to that Parent Taxonomy View and has a filter as this:

Select posts with taxonomy: Categories set by the parent View	

This would require a additional View to be created.
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#371326

Thanks. And yes that view is a Post View with a Parametric search by Taxonomy. I've seen this request in other forum posts so if it could be added to feature requests that would be great. I do know this does not mean it will ever be a feature.

When you say I would "need to hide them with Custom Code or a Custom WordPress DDBB Query" do you mean I could use javascript to hide the sub-categories until the Parent was clicked? From your experience would this be a simple code snippet or does it sound complex?

And I tried your other approach ( create a Parent Taxonomy View, where you first display all Parent Terms. The current Post View will be insert to that Parent Taxonomy View and has a filter as this: Select posts with taxonomy: Categories set by the parent View ) but I can't seem to get this to work. Any chance I could let you see my configuration to see what I'm doing wrong?

Thanks again,

Tim

#371417

I would 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

Your next answer will be private which means only you and I have access to it.

❌ Please backup your database and website ❌

✙ I would, if possible, need access to a site where only a minimal set of Plugins and a default theme is active.
This to avoid eventual compatibility issues with other software.

✙ I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site.
This is also a reason the backup is really important

✙ Please add the Links to:

- The Views Edit Screen

- The Page/Post where you insert the View

- The corresponding Front End Page/Screen

Here is what I will do:

1. Create a post view that returns Posts by a Taxonomy (parent only)
2. I will display this in a page
3. Of course this will not have a parametric Search, as a Query can be used only once every view.
4. I can not provide the custom code necessary for this as it requires a whole new Query, excluding Child Categories from the Parametric Search.

Please could you provide me the additional Infos?

Thank you for your patience.

#371680

You have the Child View querying for the Taxonomy "listing-category" once in the Parametric Search, and once in the Query Filter.

This is not possible.
In hie above suggested setup you will have a Query filter only and this will return all Posts in Taxonomies set by the parent View.

You can not -re-query this in a parametric Search.
If you need the parametric Search on this Taxonomy, you will need to use the Filter as before and that will display also the Child Terms.

Another approach is to create Links with a Taxonomy view where you list parents only.
This Links must lead to a page where you insert the Post View, which is then set to:

 Listing Categories slug in one of those set by the URL parameter wpvlistingcategory
eg. <em><u>hidden link</u></em>	

This would then enable you to click on a Term Link on one page and this will lead to a second page with the results.

You can also include both Views on the Same page, so to have a similar setup as now.

This are the 2 Possibilities you have.

Please let me know if you need help with this sort of setup.

Here is a thread that helps you achieve this:
https://toolset.com/forums/topic/cannot-figure-out-how-to-make-taxonomy-term-archive-pages-with-parametric-search/#post-364596

In this Post I elaborate how to create a View that produces a "menu" which then leads to the results.

Of course this menu can be style however you want, and the URL's can be adjusted how you like

I have not set this up on your site yet, as it requires first you to evaluate if this fits your needs.

If this does not fit the needs, you would need to go with the Parametric Search which will display Child Taxonomies as well.

I will not also add the Feature Request.

Thank you for your patience.

#371682

I have received feedback that this feature will not be implemented in Toolset.

We can have a certain Query Taxonomy only once in our Filters.

This feature would require to be able to add the Query Taxonomy twice (same taxonomy, just once parent and once child term)

THat is not the only reason, there are deeper things happening here as well.

WordPress has a flag when searching for posts belonging to a taxonomy term, when the taxonomy is hierarchical.

That flag stated whether we should include in the search results the items that belong to any children term of the curently used (even if posts are not assigned directly to it) or not.

Besides that, Users have very different ways of adding terms on a hierarchical taxonomy to posts: some add the whole tree from parent to children, some add only the children.

The result of all this is that we can not provide a consistent behavior at all, and any implementation will have Users being confused and asking for the "other way around".

We will not implement this feature.

Please do not hesitate to open a new thread if other issues or problems arise

Thank you for your patience.

#371788

Thanks for the detailed responses. And I do understand why it cannot be a feature request. I need to go over your possible solutions again more carefully but I do not think they will work for my needs. I need the child categories to appear ajax style without a page refresh when its parent category is clicked. So I'm thinking your earlier solution "You would need to hide them with Custom Code or a Custom WordPress DDBB Query" is probably the only real solution here. Did you mean that I could use a javascript snippet to hide the child categories until a user clicks on its parent category?

Tim

#371804

This is possible with elaborated JS code which I can not provide here in the Support forum as it's above the scope of it

It seems -unfortunately- that for now you need custom programming work which is beyond the scope of our support.

At this point I would suggest you consider contacting one of our certified partners from this link:
https://toolset.com/consultant/

You will get the custom assistance you need to get on with your project.

Please do not hesitate to open a new thread if other issues or problems arise

Thank you for your patience.

#373745

Hi again, I've hired a developer to create this customization. They'd like to know how they can edit the filter code/shortcode so we can add our own javascript and class to modify the filter code.

Thanks

Tim

#374289

I can not pass the call back events to use for this, this would require to test them and it equals to write the code for it.

A Professional Developer will know how to find the call back events and customize them.

You can add the JS to the JS Section of the Parametric Search Editor.

We have a extra feature in there that lets you add this very easily, it's elaborated here:
https://toolset.com/documentation/user-guides/adding-custom-javascript-views/
https://toolset.com/version/views-1-10/ > New frontend events and GUI to add callbacks

Regarding the filter itself, he might need to add a custom query filter, make it listen to URL parameters, hook it into the Views query, which provides a filter for it, and then finally maybe create custom shortcodes to display controls for that, even adding the right classnams so the natural Views parametric form workflow recognizes them.

The Views API can be found here:
https://toolset.com/documentation/user-guides/views-filters/

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#374522

Thanks, but he says he just needs to know what the call back event for the filter menu shortcode is.

Tim

#374556
This is the callback - after you chose and isnert.png
Open JS Section of Filter.png
Front End handler GUI.png
Choose the event.png

The available callbacks are to find as you see in the ScreenShot.
Any JS can be added there, and will hook in the (ScreenShot) visible callbacks.

Thank you

#374689

Very sorry for all this back and forth, I'm just not sure we're understanding things. Here is what my developer said:
For the following shortcode how can I edit the radio buttons from my theme's function file?
[wpv-control taxonomy="listing-category" url_param="wpvlistingcategory" type="radios"]

#375163

We refer to Custom Developers on our consultants Site because they are familiar with Toolset.

If you hired a Developer from there and he/she is not family with this, please inform him/her to contact us over hello@wp-types.com.

He/she can use the callbacks that I mentioned above, and our ShortCode Filters are visible in our API Section for Views, where we also elaborate on Filters that can be used to hook into a ShortCode before it's expanded.
https://toolset.com/documentation/user-guides/views-filters/

Your goal might though need a new, Custom ShortCode.

Thank you

#375775

Thought of another way this should be possible. In the parametric search filter I should be able to use conditionals right? So for example I should be able to add:

[wpv-conditional if="( '[wpv-taxonomy-slug]' eq 'music' )"]show something here[/wpv-conditional]

And inside the conditionals I could add a custom field that replicates the sub-categories.

But when I use the code above nothing appears when I select the Music category. Do conditionals not work with Ajax results or am just doing this wrong? I also tried this:

[wpv-conditional if="( '[wpvlistingcategory]' eq 'music' )"]show something here[/wpv-conditional]

Thanks,

Tim

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.