Skip Navigation

[Resolved] A search filter: first parent, then child

This support ticket is created 5 years, 6 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 7 replies, has 3 voices.

Last updated by Waqar 5 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#1270341

Tell us what you are trying to do?
The categories is hierarchical such like this:
Head1
Sub a
Sub b
Head 2
Sub c
Sub d
Sub e
Head 3
I want to make a view with a filter.
First I want to display only the Head's. After clicking on a Head, by example Head1, I want to show up for the user a new filter with only the options Sub en Sub b.

Is there any documentation that you are following?
I'm reading your user guide.

Is there a similar example that we can see?
I don't know at this moment.

#1270453

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand, you have a category, on the first page, you want to list all categories and when you click on those category name you want to display all associated posts to that category - correct?

#1271289
toolset-filtering.jpg

Hello Minesh,

Sorry that I didn't explain my question clear. Another try.

Situation
CATEGORY headtheme1 consist of SUBCATEGORIES subtheme a, subtheme b
CATEGORY headtheme2 consist of SUBCATEGORIES subtheme c, subtheme d, subtheme e
CATEGORY headtheme3 consist of SUBCATEGORIES subtheme f, subthema g
and so on

What I want
2 filters with pulldown lists.

The FIRST filter shows only the CATEGORIES headtheme 1, headtheme 2 and headtheme3

When in the FIRST filter headtheme 1 has been selected then is display in the SECOND filter only the subcategories subtheme a, subtheme b
When in the FIRST filter headtheme 2 has been selected then is display in the SECOND filter only the subcategories subtheme c, subtheme d and subtheme e
When in the FIRST filter headtheme 3 has been selected then is display in the SECOND filter only the subcategories subtheme f, subtheme g
and so on

How to show
Both filters are on 1 page. On top the 2 filters, below in a table the post.
First visit on the page: all posts show up
By using both filters only the posts in the choosen subcategory shows up.

In the attachment a drawing how the page looks like on the first visit.

I hope this helps.

#1271441

Minesh
Supporter

Languages: English (English )

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

Ok I got it, you need dependent dropdown but there is no option to display the dependent dropdown.

The only way you can display the dependent dropdown is using post types with the relationship.

Please check the example with the following reference site link State and City:
=> hidden link

You can register test site to review how it was setup. It’s totally free.
=> https://toolset.com/faq/how-and-why-to-create-a-test-site-in-discover-wp/

You should try to crate a test site on our free test platfrom discover-wp.com and check how the state -> City dropdowns are configured where state and city are post types and with one to many relation:
=> https://discover-wp.com/register/?site_type=713&layouts=yes

#1274299

Thank you for your reaction.

My idea was: using several content types for my site. Every content type uses the same taxonomie.
In this way the user has the option to search through all the content types only belongs to one category.

I don't know yet if that is going to work if I use relationships between post types.
That means: a user has to make a relationship and has to choose 2 categories (headtheme and subtheme) too.
2 things to do (for the same) entails a greater risk of errors.

Or do I make a mistake?

#1274529

Hi there,

Thanks for writing back.

Minesh is on a personal day-off today and I'll be following up on this ticket.

>> My idea was: using several content types for my site. Every content type uses the same taxonomie.
>> In this way the user has the option to search through all the content types only belongs to one category.

- Whether you'll use the originally planned approach of hierarchical taxonomy or the suggested approach of post-relationship, the search between the multiple content or post types will work the same way.

In your search's post view, you'll select the post type for example "Posts" that you'd like to get the results from, in either case.
( ref: https://toolset.com/documentation/user-guides/front-page-filters/ )

However, the use of multiple post type will complicate this. Can you add all your posts which need to be included in the search in a same post type? To differentiate/segregate them, you can assign a custom taxonomy, as a workaround.

If you decide to use a single post type for this search, here is an overview of how this will need to be set up:

1. Suppose you'd like to include the "Posts" post type in your search.

2. To develop a conditional and multi-level search filter, you'll register two new custom post types:

a). Heads
b). Subs

3. As the name indicates, you'll add all "head" items as individual posts in the "Heads" post type and all the "sub" items as posts in "Subs" post type.

4. To make a connection between these two, you'll create a "one-to-many" post-relationship, between "Heads" and "Subs", which means that "each head can have multiple subs".
( ref: https://toolset.com/documentation/post-relationships/ )

5. Next, you'll create another "one-to-many" post-relationship, between "Subs" and "Posts", which means that "each sub can have multiple posts".

Once these relationships have been setup, you can use the following guide to create a front-end search filter:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/how-to-filter-posts-by-their-ancestors/

>> I don't know yet if that is going to work if I use relationships between post types.
>> That means: a user has to make a relationship and has to choose 2 categories (headtheme and subtheme) too.
>> 2 things to do (for the same) entails a greater risk of errors.

- The number of steps that user will have to take will remain the same whether hierarchical taxonomy or post-relationships are used.

The heads, subs and their relationships will be added by you (the website's admin), same as in the case of heirarichal taxonomy.

At the time of creating a post, user will only specify the "Sub" to attach to it and the parent "Head" will automatically get linked through that "Sub".

To summarize, you can either:

a). use the heirarichal taxonomy for the search filter and the search won't have the two field, parent and child selection filter or
b). use post-relationships to have the two field, parent and child selection filter in the search, but will also have to add all searchable posts, in a single post type.

For an out-of-box and personalized custom developend workaround, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1277353

Thank you Waqar for your extensive reaction. This is clear for me now.

But I have an additional question about relationships between users and a post.
I've been reading your page: https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/
I understand that the field "post author" is the linking pin.

Our situation
The most off our users will not create a new post, so there isn't a "post author"-field for these users.
In our example, step 4 of the flow, the user will not do that!
Is there another way to mirror user information in a custom post type?

Our idea is
We add an additional field (a field to choose a sub) to the user register form. When a user registers with our site he or she has to choose a sub. Because of a relationship between the user profile (or custom post type) and the custom post type Sub, the name of the user will be displayed.

I hope you understand our idea and give us a hand.
Thanks!

#1277591

Hi,

Thanks for the update and glad that my message helped.

As for your new question, your observation is correct and our recommended approach towards connecting "Users" and "Posts" is through a new middle custom post type like "Contractor profile", as suggested in the guide.
( https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/ )

Your planned approach of storing "Sub" post's reference ( specifically that post's ID ) in a custom user field, with each user's profile can work, if your goal is only to:

a). show which "Sub" is attached to a user, when showing a single or multiple users
and/or
b). show which users have a particular "Sub", when showing a single or multiple Subs

However, it is important to note that front-end search filters only work in "Post" views and not in "User" views. If your goal is to show a list of users through a view, which also includes front-end search filters, than you should not be using this custom field approach and should be following the approach of using a middle custom post type layer for the connection, as suggested in the already referenced guide.

If you're fine with that limitation and would like to continue with user custom field approach, you can add a new "Select" type field for the users and leave the options, as they can be generated programmatically from the available posts in "Sub" post type, using the "wpt_field_options" filter.

You'll find the example code snippet on how to use it, in this reply:
https://toolset.com/forums/topic/custom-field/#post-1190447

In that code snippet, the "Dogs Sire" and "dogs" will replace the actual title of your new user field and the actual slug of the "Sub" post type, respectively.

I hope this clarifies and please let me know if you have any question or concern related to what's covered in this reply.

For future reference, please note that as per our support policy ( https://toolset.com/toolset-support-policy/ ), only one topic or issue can be addressed through a single ticket.

You're welcome to open a new ticket for each new topic.

regards,
Waqar