Skip to content

Commit

Permalink
Merge pull request #3524 from 10up/fix/3517
Browse files Browse the repository at this point in the history
Fix: Restrict applying a facet filter to the query if the filter value is empty.
  • Loading branch information
felipeelia authored Jul 4, 2023
2 parents 811bd8b + 7f0cfd4 commit 7723409
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions includes/classes/Feature/Facets/Facets.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ public function get_selected() {

foreach ( $filter_names as $filter_name => $type_obj ) {
if ( 0 === strpos( $key, $filter_name ) ) {
if ( empty( $value ) ) {
continue;
}
$facet = str_replace( $filter_name, '', $key );

$filters = $type_obj->format_selected( $facet, $value, $filters );
Expand Down
6 changes: 6 additions & 0 deletions tests/php/features/TestFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public function testGetSelected() {
$this->assertSelectedTax( array( $term->slug => true ), 'taxonomy', $selected );
$this->assertArrayHasKey( 'post_type', $selected );
$this->assertSame( 'posttype', $selected['post_type'] );

// test when filter value is empty.
parse_str( 'ep_filter_category=&ep_filter_othertax=amet&s=', $_GET );
$selected = $facet_feature->get_selected();
$this->assertArrayNotHasKey( 'category', $selected['taxonomies'] );
$this->assertArrayHasKey( 's', $selected );
}

/**
Expand Down

0 comments on commit 7723409

Please sign in to comment.