search by multiple categories AND keyword returns no results
-
Hi;
When i search by multiple categories AND search keyword, the result set is empty although all search criteria are met. The same search query returns the expected results when i use the wordpress default search instead of relevanssi.
Is that a known limitation or can it be fixed ?
example:
All of the following queries should return at least one entry:
(is ok) https://blog.machinimatrix.org/?cat=62&s=random
(is ok) https://blog.machinimatrix.org/?cat=62&type=541&s=
(broken) https://blog.machinimatrix.org/?cat=62&type=541&s=randomHowever the last query returns nothing.
====
details: I have setup a search form which creates 3 parameters:
cat (main search category)
type (subcategory)
s (search keyword)I have added an action for ‘parse_request’ into functions.php which changes the $query->query_vars. When i now call the blog as follows:
https://the.blog.org/?s=mysearch&cat=1&type=2
Then the parse_request function changes the $query->query_vars to:
Array ( [s] => mysearch [category__and] => Array ( [0] => 1 [1] => 2 ) )
Maybe something is missing here ?
====
The function code:
add_action( 'parse_request', 'category_search_logic', 11 ); function category_search_logic( $query ) { // Nothing that we should care about: if ( ! isset( $query->query_vars[ 'cat' ] ) ) { return $query; } // Store session variables for later use if(isset($_GET['cat'])) { // split categories query on a space to get IDs separated by '+' in URL $categories = explode( ' ', $_GET[ 'cat' ] ); $_SESSION['cat'] = $categories; } else $categories = ''; if(isset($_GET['type'])) { $subcategory = $_GET['type']; $_SESSION['type'] = $subcategory; } else { $subcategory= ''; $_SESSION['type'] = 0; } if ( $categories == '' ) return $query; // create list of restrict categories if ($subcategory != '' && $subcategory != 0) { array_push($categories, $subcategory); } if ( count( $categories ) > 1) { unset( $query->query_vars[ 'cat' ] ); $query->query_vars[ 'category__and' ] = $categories; } return $query;
- The topic ‘search by multiple categories AND keyword returns no results’ is closed to new replies.