Posted on

Custom post type filtering produces empty results

If clicking “Filter” in a custom post type admin view comes up with an empty results with the first click and proper results on the second click when Relevanssi is installed and enabled in admin, the solution is to add these functions to your functions.php:

add_filter('relevanssi_admin_search_ok', 'relevanssi_disable_filter_admin', 10, 2);
function relevanssi_disable_filter_admin($ok, $query) {
    if (empty($query->query_vars['s']) || $query->query_vars['s'] == " ") {
        return false;
    }
    else {
        return $ok;
    }
}
 
add_filter('relevanssi_search_ok', 'relevanssi_disable_filter');
function relevanssi_disable_filter($ok) {
    global $wp_query;
    if (empty($wp_query->query_vars['s']) || $wp_query->query_vars['s'] == " ") {
        return false;
    }
    else {
        return $ok;
    }
}

I’m not exactly sure what’s causing the problematic behaviour – I haven’t been able to reproduce the error myself, and it may be somehow related to using Toolset – but these functions take care of the problem.

  • Becky Lund

    Thank you! This fixed the empty results on the front-end too. Yes, toolset was the issue for me

  • This fixed getting 0 results when the URL on an archive page contained “?s=” (empty search query). I do not have Toolset installed.