Skip Navigation

[Resolved] How to display custom search dropdown for subcategories of a certain category?

This support ticket is created 6 years, 10 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 8.71 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 4 replies, has 3 voices.

Last updated by thibaudL 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#605989

Hi,
I am building a large website as an online library. I have a custom type post called Books.

Say I have 2 categories:
- History (with 2 subcategories: Egypt, Greece)
- Arts (with 2 subcategories: Sculpture and Painting)

then I have 4 books:
1- Sculpture in Ancient Egypt (needs categories: Egypt and Sculpture)
2- History of Egypt (needs category: Egypt only)
3- Painting in Modern Greece (needs categories: Greece and Painting)
4- History of Greece (needs category: Greece only)

I am trying to create a custom search for each of the main categories (History and Arts), that Display a dropdown list of the subcategories.

So when the visitor enters the page that I will create for the history section, they can see the history books (1, 2 &4), and a custom search view with a dropdown list that shows the history subcategories,
so when a visitors chooses "Egypt" from the dropdown list, they see books 1 and 2, while if they chose "Greece" they see book 4 only.

The problem is that If I chose the category "History" from the filters, is disappears from the query filters, and gets greyed out in the "Filter Editor" section.

the workaround I thought of is to create a custom taxonomy and call it "Main Categories" and add to it "History, Arts", and create the custom search view using the "main categories" and the "categories" becomes the search parameter.

it worked partially, however, because some books have the 2 main categories (books 1 and 3), the resultant dropdown contains both trees, which does not make the page a "history section".

please check the dropdown list here:
hidden link

Another workaround I thought of is creating a custom taxonomy for each main category, but this will result in around 15 taxonomy boxes for me, which is a big load on the backend.

So my question is whether there is a way to achieve what I want. if not, is there an alternative way?

please note that this is a very basic example. my real website will contain more than 500 subcategory in aroung 15 fields, and growing, so i can't manually keep adding categories, otherwise i will keep editing the views forever.

Thanks in advance.

#606092

There's not a simple way to accomplish this type of View filter system. In order to show different dropdowns for History, Arts, and your other categories, there are essentially 3 options.
1. Create custom taxonomies for each dropdown. As you said, this will introduce something like 15 boxes to manage these terms, but it's the easiest to setup and it works with AJAX pagination and AJAX search updates. It also provides built-in archives for these terms using WordPress's standard archives system.
2. Instead of custom taxonomies, use custom fields. Each custom field can be a select field with the different subcategories as options. This is also fairly easy to set up, but does not allow you to use the standard WordPress Archive systems that taxonomies allow. This works well with AJAX pagination and AJAX search updates.
3. Use custom code to create your own filters using JavaScript, PHP, and the wpv_filter_query API. This approach is more difficult to set up and may not work with advanced settings like AJAX search and pagination updates. More information about the wpv_filter_query API here:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Keep in mind that when you create a parametric search form like this, the only way to pre-select some filters in this View is to use URL parameters. So if you want to direct the User to a page that has Greece and Painting pre-selected, you must use a URL like this: yoursite.com/search-page?wpv-location-taxonomy=greece&wpv-art-taxonomy=painting

Another thing to consider is that WordPress Archives can be created with custom search filters, with some limitations. For example, let's say you want to show an archive of Painting-related Books. So you create a WordPress Archive filtered by "painting". Now you can set up other search filter criteria, but you cannot use the "Art" filter again. That would introduce a logical problem: how can a painting archive be filtered by another "art" term? It cannot.

#1168482

Hi Christian,
I have 90 categories, i create a normal page for each category instead of using taxonomy because i need to add content to each category page.
So I manually insert the views shortcode. Apparently it's the best way to do it. And just forget the archives template etc.

Now I also want to add a filter for each category and I'm going for option 2. Because i'm exactly in this case "This is also fairly easy to set up, but does not allow you to use the standard WordPress Archive systems that taxonomies allow."

Could you please be more precise about adding filed to filter inside a specific category?
Do you mean each CPT just need a custom field with the name of the "category"?
And with Views how do you load a list of CPT with a specific custom field, and not all of them?

#1168486

To make it easy :
I'm trying to show only one single category on a page, and filter by tags on the top.

#1168491