Skip Navigation

[Resolved] Populate dropdown with child objects, and when one selected list grandchildren

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a custom search View that I can place on the single post of my top-level hierarchical post type - the Grandparent post. In that search View I want to show a filter where the User can select any posts of the second-level post - the Parent post. The matching third-level posts - the Child posts, should appear beneath the search form.

Solution: In order to accomplish a parametric search of hierarchical post types like this, you must use URL parameters to predefine any level of the hierarchical relationship. If you do not want to include these parameters in your site links, you could consider a custom approach that redirects Users from the clean URLs to the parameterized URLs.

Relevant Documentation: https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/
https://toolset.com/documentation/user-guides/front-page-filters/

This support ticket is created 6 years, 11 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
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 2 voices.

Last updated by KenG8581 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#608897

Relationships between post types:
Sector has many Areas
Area has many Processes

When displaying a specific Sector (using the default template of Sectors), we would like to list all Processes (that are grandchildren of the Sector).
And include a filter option that allows the user to include all Processes, or filter for a specific Area (child of Sector).

So, basically a page that contains
- a dropdown field populated of Areas that are children of current Sector, and a *all option.
- a list of Processes that are children of the selected Area, or grandchildren of the current Sector if the *all option is selected.

We have searched the documentation, but havent found the solution.

#609128

Hi, are you describing a custom search View or a CRED form? I wasn't clear from your description. If it's a custom search View, you can take a look at the Real Estate reference site over at discover-wp.com to see a similar setup. On the homepage you will see a custom search form with State > City > Home as the post type hierarchy. This View uses the advanced option "Only show available inputs" so that the hierarchical filters behave like you're describing. On the reference site, "State" corresponds to "Sector," and "City" corresponds to "Area". Homes correspond to Processes.
I have a demo site set up here where you can see these filters: hidden link

You can set up your own demo site at discover-wp.com and get access to the backend to see how it's all put together. Let me know if I've misunderstood how you want things to work. We also have a bit of documentation about this topic here:
https://toolset.com/documentation/user-guides/front-page-filters/advanced-settings-custom-search/#dependent-parametric-search

#609462

Hi Christian
That provided me with enough to get it work, but not in the way we would like.
First of all - we are talking about View 🙂

I was looking for a way to incorporate the search view in a the default template for the post type Sector.

So - in the real estate example, when I view a post type of State, then I would like to have a search dropdown populated with all Cities (of the current State), and underneath that - a list of Homes (just like the example you directed me to).

The difference is that in the real estate example, the user start out of context, select the state, then the city and then the home.
In our case, we start out on the template of a state and would then like to filter homes by selecting city (of the state in context).

If I modify the URL (remove the /?wpv-relationship-filter-***), then all homes in all cities in all states are shown. And that is not useful in our case.

How can we do it otherwise?

Best
Ken

#609486

If you want to use a hierarchical post relationship filter in a parametric search form, the only way to predefine any level of that relationship is to use a URL parameter. There's no way around it without a lot of custom code. You can hide the Sector select field from your Users, but you must still include the URL parameter. If you don't want to link to URLs with these parameters, I think you could redirect your users automatically somehow using a redirection plugin or custom JavaScript. Something like yoursite.com/sector/first-sector must be redirected to yoursite.com/sector/first-sector/?wpv-relationship-filter-sector=12345. When the page reloads with those parameters in the URL, the Sector select field would be preset, and hidden, and the corresponding Areas would show in a select filter. The matching Processes would be displayed below.

#609885

Thanks Christian for your support.
We will see how we best set it up, but now we are in progress 🙂