Skip Navigation

[Resolved] Setting a default filter value on a view

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

Problem: I created two CPTs: Events and Profiles. I have a View of Events displayed in the template for Profile posts, and I would like to only display Events where the title of the current Post can be found in the "notes" WYSIWYG field on the Event post.

Solution: Configure the notes custom field Query Filter to use a shortcode attribute and pass the current Profile post title into that shortcode attribute like so:

[wpv-view name="your-events-view" search="[wpv-post-title]"]

This technique is called passing arguments to views, and allows you to create Views with dynamic Query Filters.

Relevant Documentation:
https://toolset.com/course-lesson/passing-arguments-to-views/
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-title

This support ticket is created 2 years, 9 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jane 2 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#2102339

Hi,

I'm trying to create a view (classic) that will do the following.

The view is searching post type Events, and is installed on post type Profile.

I want it to display all the posts that contain the value of the post title (from profile) in the WYSIWYG field 'note' from events.

I created a custom search that does this and it works fine BUT I do not want the user to input a value, I want it to produce the results automatically.

Any ideas ?

#2102547
Screen Shot 2021-06-29 at 4.29.41 PM.png

Hello, you can force a View to always search for a dynamic text string by setting up the Post Search Query Filter to respond to a shortcode attribute. Then you can use a shortcode attribute in the View shortcode to pass the current post's title into the filter. First, I suggest removing the normal text search input from the View's Search and Pagination panel. The standard text input wpv-filter-search-box shortcode will look something like this:

[wpv-filter-search-box output="bootstrap"]

Delete that shortcode to delete the input and decouple the filter control from the corresponding Query Filter. Save the View and reload the View editor page to force the Query Filter to update.

If you cannot see the Query Filter panel, you must activate it. Scroll to the top right corner of the screen, click "Screen Options" tab to open the screen options panel and activate Query Filters. You should be able to see a Post Search Query Filter now. In the filter configurations, choose the option to search for text set by a shortcode attribute "search".

Then you must insert this View in the template for Profiles and pass the current Profile post's title into the search filter automatically. The syntax looks like this:

[wpv-view name="your-events-view-slug" search="[wpv-post-title]"]

That should be enough to pass the current Profile post title into the search filter, and the View will always return Event posts with matching criteria. This assumes your Events View was working correctly before, when the input field existed.

Let me know if this isn't working like you expect, or if I've misunderstood the problem.

#2104077

Thanks for pointing me in the right direction.

I modified my custom field "note" to use the shortcode setting and everything is working as I want it to.

Thanks again.

#2104079

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.