Problem:
I want to create a view that shows a search results page. I want to prepopulate the search term with the content of a custom post field (via shortcode). And I want the page to load automatically the results when first loading the URL. Is it possible to achieve this with the plugin?
Solution:
I assume we are talking about the search box outputted from Views shortcode [wpv-filter-search-box].
It needs some custom codes, for example, when user first loading the URL, you can use Views filter hook wpv_filter "wpv_filter_query" to trigger a custom PHP function, in this PHP function, prepopulate the search term and the search result.
For example, you can add below codes into your theme/functions.php:
add_filter('wpv_filter_query', 'my_func', 1, 3); function my_func($query_args, $view_settings, $view_id){ if($view_id == 123){ if(!isset($_GET['wpv_post_search'])){ $_GET['wpv_post_search'] = 'my search term'; } } return $query_args; }
Please replace 123 with your Views's ID.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
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: Asia/Hong_Kong (GMT+08:00)