Skip Navigation

[Resolved] Filtering Posts With Views

This support ticket is created 4 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.

Our next available supporter will start replying to tickets in about 3.16 hours from now. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by michaelO-8 4 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1400037

Tell us what you are trying to do?

Using a view I am trying to filter a certain post type by various criteria (location, open positions, etc). I am using the "select dropdown" as one input to filter views and existing custom fields populate the choices for the dropdown. If a user creates a post and inputs "Florida", in the location dropdown, "Florida" becomes an option to select. I only want data from children of the Post where the view is shown to populate the select dropdowns.

However, I have noticed that the choices are populated with not just the custom field values from posts that are children of the Post where this View is shown, but all posts of this type. This means that even on other posts with different where "Florida" has not been inputted, it can be seen as a choice. Ideally, I would like to limit custom field values to those that are children of the Post where the View is shown, which seems possible for displaying the posts. Is this possible or do I have to create a new post type each time?

What is the link to your site:

Here is a Post where there are children with various values: hidden link

Here is another Post where there are no children, but there are still choices for the dropdown selects, even with no children: hidden link

#1400353

Hello,

I assume we are talking about this case:
Two post types:
- Company
- Jobs (with custom fields: location, open positions, etc )
One-to-many relationship between post types "Company" and "Jobs"

You are going to do these:
- Query "Company" posts
- filter by custom fields of post type "Jobs"

If it is, it is not possible within Views plugin, since Views plugin is using WP_Query to query posts, when you query "Company" posts, you can only filter by custom fields of same post type "Company", can not filter by custom fields of other post types.

In your case, you might consider these:
Setup a post view:
- Query "Jobs" posts
- Filter by custom fields: location, open positions, etc
- In view's loop, display it's parent company post information:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

#1401055

Hi Luo,

Thank you for the help, but maybe I was not clear enough about my use case.

There is only one type of post being used (I think like what you are recommending). The post type is called "Booth" and it is is the child of a post type called "Fair". All of the custom fields in the filter are data from the post type "Booth", including location, open positions, etc. On each "Fair" post, a user can filter to see "Booth" posts that meet their criteria. The options are populated with data from all booths that are created.

Ideally, I would like filter data to be populated with only custom field data from the child post type "Booth" for each "Fair". In the example "Test Fair 2" hidden link, there are no children "booth" posts yet, so I would like for there to be no options to select for "open positions" and "location" yet. If there is a "Booth" added to this parent post "Test Fair 2" with the location "New York", then I would like New York to be added as an option to filter in the location dropdown.

It seems like this should be possible because I was able to successfully show in the view filter results with only children posts "Booth" on the parent "Fair" page. If filter data could also only come from custom fields from these booths, that would be great.

If it would be helpful to log in to the website to see the relationship structure, I would be happy to give you access.

#1401317

OK, I have enabled the private message box, please provide your website credentials in below private message box, thanks

#1405345

Thanks for the details, I can log into your website, will update here if there is anything found

#1405381

Since the problem page is wordpress page, in your case, this post view should display insider a single "Fair" post.

So I have done below modifications in your website:
1) Create a new "Fair" post, and connect some new "Booth" posts:
hidden link

In post content, display view's shortcode:
[wpv-view name="sort-companies-at-fair-4-fields"]

2) Edit the post view "sort-companies-at-fair-4-fields":
hidden link
click link "Screen options", option "View purpose" choose: Full custom display mode

in section "Custom Search Settings", enable option "Let me choose individual settings manually"-> "Show only available options for each input"

Test above "Fair" post in front-end:
hidden link

I can see it works fine, the options are limited.

Please check if it is what you want.

More help:
https://toolset.com/documentation/user-guides/views/front-page-filters/advanced-settings-custom-search/
Advanced Settings for Custom Search

#1408681

Thank you, this is exactly what I was looking for. Thank you also for the documentation.