Problem:
I have a custom search which filters by post ID based on URL query.
Right now for an empty query the view returns all results.
Is there a way to return the [wpv-no-items-found] bit intstead for this particular view?
Solution:
f you pass empty URL parameter "my-url-param" to view, view will output all result.
In your case, you can change it with Views filter hook "", for example add below codes into your theme/functions.php:
add_filter( 'wpv_filter_query', 'show_empty_default_func', 99, 3 ); function show_empty_default_func( $query_args, $setting, $view_id ) { if($view_id == 12345) { if( isset($_GET['my-url-param']) && $_GET['my-url-param'] == '' ) { $query_args['post__in'] = array(0); } } return $query_args; }
Please replace 12345 with your view's ID, replace "my-url-param" with your URL parameter
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)
Ce sujet contient 3 réponses, a 2 voix.
Dernière mise à jour par Il y a 6 années et 8 mois.
Assisté par: Luo Yang.