Tell us what you are trying to do? I would like for a user to be able to create a project (they should be able to create multiple projects within their account). The user will have a set of checkboxes in a project form and based on their selections, they will be shown a list of businesses that meet that criteria. Similar to Angeslist.
I am thinking of creating two custom post types: Project and Business. Setting the relationship of One (project) to Many (business)... I am just not sure how to filter the business list within a project that only shows the businesses that meet the criteria.
Hello,
You can setup relationship filter within custom search form, for example, create a page, display a view block:
- Query "Business" posts
- Filter the result by relationship between Project and Business
- In view's loop, display Business post information.
See our document:
https://toolset.com/course-lesson/creating-a-custom-search/#add-filters-based-on-post-relationships
section "Add filters based on post relationships"
I'm not sure that is what I need exactly. I am planning to have a list of businesses, and each will have its own list of zip codes that they serve (75005, 75006, 75008, etc.). Then the customer will complete a form (which creates a project post) and they will enter their zip code. When the customer views their project post, I would like for them to see a view that lists all the businesses that serve their zip code. So basically filtering a list of businesses based on if one of their zip codes matches the customer's zip code.
For the ZIP issue, you can try these:
1) create a new single line field "ZIP" in post type "Business":
https://toolset.com/course-lesson/creating-custom-fields/
2) Create a post form for creating new "Business" post, so your user can submit the form in front-end and create new "Business" post:
https://toolset.com/course-lesson/front-end-forms-for-adding-content/
3) Then create a page "Find a Business", display a view block, filter the result by the "ZIP" field:
https://toolset.com/course-lesson/creating-a-custom-search/
Can there be an automatic filter inside a post? So, if I have the list of businesses on the post page, and it is automatically filtered based on the zip code entry of the post and shows only the businesses that have a matching zip code?
Yes, it is possible.
For example, you can get the custom field "ZIP" value with types shortcode:
https://toolset.com/documentation/customizing-sites-using-php/functions/#textfield
Then pass above value to below post view as shortcode attribute:
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
Setup above post view as below:
- Query businesses posts
- Filter by custom field "ZIP" value = shortcode attribute value
https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/#source-for-compare-value
Shortcode attribute The value for the filter comes from an attribute in the View shortcode