I have a first post type called "Seasonal Products"
I have second post type called "Vendors"
An example seasonal product is "Apples"
On the "Apples post" I want to display all Vendors that might sell apples.
The vendors enter their products as part of the post body
I want a view that uses the post title from the product page "Apples" to search the Vendors and show all vendors that use the word apples in their post body.
Is there a way to do this? I could not figure it out.
Hello and thank you for contacting the Toolset support.
I can see two ways of doing so:
- By passing the post title to the view's query filter via a shortcode argument.
- By hooking into the view's query arguments and modify them to introduce the search clause.
The first solution cannot be built completely using the blocks editor, because it will need to generate the view using a shortcode in order to pass the post title to it. Add a query filter to the view with the search text and configure it to take the search terms in a shortcode argument. You will have to name the shortcode. Let's say it's called "product". Then you can pass it to the view like this:
[wpv-view name="Name or slug of the view" product="[wpv-post-title]"]
The nested shortcode wpv-post-title will return the title of the current page. Please note that you will need to register the shortcode wpv-post-title in Toolset->Settings->Front-end Content in order to use it inside the wpv-view shortcode.
The second solution will need custom code. The custom code will hook into the wpv_filter_query filter and change the view's query arguments. The query is an instance of WP_Query, and it follows its arguments
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
- https://developer.wordpress.org/reference/classes/wp_query/#search-parameters
I hope this helps. Let me know if you have any questions.