Skip Navigation

[Resolved] Show search result in a view

This support ticket is created 3 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: Africa/Casablanca (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Jamal 3 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#2160149

Ian

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.

#2160651

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.