Problem:
The customer wanted to create a search form with drop-down options for filtering academic texts on their website, aiming to replicate a search functionality similar to that on the Jeb Dunnuck site. They faced difficulties implementing this using Toolset Views with the legacy editor.
Solution:
To achieve the desired search functionality, the customer was advised to add a select dropdown for post type filters within their view and use the following code for implementation:
[wpml-string context="wpv-views"]Post Type:[/wpml-string] [wpv-control url_param="wpv-post-type" type="select" values=",page,post" display_values="All,Page,Post"]
Next, they were instructed to add a custom function to their theme’s functions.php file to modify the query based on the selected post type:
add_filter('wpv_filter_query', 'post_type_filter_func', 10, 3); function post_type_filter_func($query_args, $settings, $view_id) { if ($view_id == 9999 && isset($_GET['wpv-post-type'][0]) && !empty($_GET['wpv-post-type'][0])) { $query_args['post_type'] = $_GET['wpv-post-type'][0]; } return $query_args; }
The customer was reminded to replace 9999 with the actual View ID.
For displaying the search form and results on different pages, they were guided to insert the View on the results page using:
[wpv-view name="my-search-view" view_display="layout"]
And on the search form page with:
[wpv-form-view name="my-search-view" target_id="123"]
Here, 123 should be replaced with the ID of the results page.
Relevant Documentation:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/
https://toolset.com/course-lesson/displaying-search-results-on-a-different-page/
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 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Sao_Paulo (GMT-03:00)
This topic contains 5 replies, has 3 voices.
Last updated by 2 months ago.
Assisted by: Mateus Getulio.