Support » Plugin: Relevanssi - A Better Search » Empty value for "s" returns no results

  • If the value for s is empty, no results are shown. Shouldn’t this not affect the search results? By default without the plugin an empty value of s results all posts.

    Several themes use an advanced search which allows the category etc to be selected and for the search field to be left blank (ie. passed as s=&cat=… to the query string).


Viewing 2 replies - 1 through 2 (of 2 total)
  • I ended up having to do this to say the search was not okay:

    function ocrc_disable_relevanssi_search_if_empty( $search_ok ) {
    	if ( isset( $_GET['s'] ) and ! trim( $_GET['s'] ) )
    		$search_ok = false;
    	return $search_ok;
    add_filter( 'relevanssi_search_ok', 'ocrc_disable_relevanssi_search_if_empty' );

    but it still returned no results with s= (blank) in the query string, so I also had to do this:

    function ocrc_remove_relevanssi_hooks_if_search_empty() {
    	if ( isset( $_GET['s'] ) and ! trim( $_GET['s'] ) ) {
    		remove_action( 'init', 'relevanssi_query' );
    		remove_filter( 'posts_request', 'relevanssi_prevent_default_request' );
    add_action( 'init', 'ocrc_remove_relevanssi_hooks_if_search_empty', 1 );

    If there’s another filter I’m missing let me know, and might be worth adding something like this for the next update?


    Plugin Author Mikko Saari


    This function alone should be enough:

    add_filter('relevanssi_prevent_default_search', 'ocrc_disable_relevanssi', 10, 2);
    function ocrc_disable_relevanssi($disable, $query) {
        if (empty($query->query_vars['s'])) $disable = true;
        return $disable;

    And yes, this will be included in the next version.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Empty value for "s" returns no results’ is closed to new replies.