Skip to content

Commit

Permalink
Merge pull request #392 from pantheon-systems/389-fix-filtering-empty…
Browse files Browse the repository at this point in the history
…-search

Correctly apply Solr query modification even when search is empty
  • Loading branch information
danielbachhuber authored Dec 18, 2018
2 parents 3e54627 + fc7238d commit e2f133c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/class-solrpower-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private function build_query( $query ) {
'post__not_in' => '-ID',
'name' => 'post_name',
);
if ( ! $query->get( 's' ) && ! $query->get( 'solr_integrate' ) ) {
if ( ! $query->is_search() && ! $query->get( 'solr_integrate' ) ) {
return '';
}

Expand Down
14 changes: 14 additions & 0 deletions tests/phpunit/wp_query/test-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ function test_simple_wp_query_solr_integrate() {
wp_reset_postdata();
}

/**
* Solr Power should correctly apply filters even when search string is empty.
*/
function test_wp_query_solr_search_empty_string_applies_filters() {
$this->__create_test_post();
$this->__create_test_post( 'page' );
$query = new WP_Query( array(
'post_type' => 'post',
's' => '',
) );
$this->assertTrue( $query->posts[0]->solr );
$this->assertCount( 1, $query->posts );
}

function test_wp_query_paged() {
$this->__create_multiple( 15 );
SolrPower_Sync::get_instance()->load_all_posts( 0, 'post', 100, false );
Expand Down

0 comments on commit e2f133c

Please sign in to comment.