Skip Navigation

[Resolved] Trying to use search string filter in views

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

Problem:
How to pass a search string to a View that includes a text search?

Solution:
You pass the search term using a wpv-view shortcode attribute, as described in the linked documentation.

Note that you can only pass shortcode attributes when inserting the View by shortcode, you cannot pass attributes when using a Views cell in a Layout, for example. In that case you would need to replace the Views cell with a Visual Editor cell and insert the View via shortcode.

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 6 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by chrisC-25 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1126515
Screen Shot 2018-10-12 at 2.15.56 PM.png
Screen Shot 2018-10-12 at 2.16.05 PM.png

Hi

I have a post type called "artists" this shows a music artist. In the "layout" for that post type I want a view that pulls in any related items from a different post type called "news". I have built the view and want to filter it by the name of the artist in the current post.

For example if the Post is for artist "Kiss" the view in the layout should pull any "news" posts related to the search term "kiss".

This seems like it should be simple but I am struggling. In the post search filter I am trying to add [wpv-post-title] as the search term. This does not work......

See screenshots.

Thanks

#1127351

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Chris

I didn't test this but I'm guessing the wpv-post-title shortcode wouldn't be expanded in that scenario.

What you should do is pass the title to search by as a shortcode attribute.

You can see that in your longer screenshot, "Search for a text, set by the Views shortcode attribute:"

By default it is suggesting "search" as the attribute (which you could change), so where you insert your View in the template for Artists you would add the post title (for the Artist) as a search attribute like so:

[wpv-view name="news" search="[wpv-post-title]"]

The title shortcode will be expanded in that scenario.

https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#1127546
Screen Shot 2018-10-15 at 10.41.41 AM.png

Okay but I do not understand where I put this:
[wpv-view name="news" search="[wpv-post-title]"]

I try adding it to the "Search for a text, set by the View shortcode attribute:"

and I get an error, see screenshot.

Thanks

#1127554

I figured it out, I need to use that shortcode instead of inserting the view in the layout.

Thanks!