Skip Navigation

[Resolved] Views Search – show no results until search option entered, and add pagination

This support ticket is created 6 years 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 30 replies, has 3 voices.

Last updated by zacharyL 5 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#1796907

The last submission works out of the box for me. Thanks for the solution!

Just change '37' to your view id(s) (comma separate your values if you have more than one view that needs included), and you should be good to go.

/**
 * No initial results
 *
 * Don't show View results until a filter has been applied
 *
 * Tests for custom field filters, taxonomy filters, or text searches
 */
function tssupp_no_initial_results($query_results, $view_settings, $view_id) {
 
    $target_views = array(37); // Edit to add IDs of Views to add this to
 
    if (in_array($view_id, $target_views)) {
 
        // if there is a search term set
        if (!isset($query_results->query['meta_query']) && !isset($query_results->query['tax_query']) && !isset($query_results->query['s']) && !isset($_REQUEST['toolset_maps_distance_radius']) && !isset($_REQUEST['search'])) {
            $query_results->posts = array();
            $query_results->post_count = 0;
            $query_results->found_posts = 0;
        }
    }
 
    return $query_results;
}
add_filter('wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3);