diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index 58760a3198..48e6c24a98 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -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 ); diff --git a/tests/php/features/TestFacet.php b/tests/php/features/TestFacet.php index bcf9551424..381ca387a7 100644 --- a/tests/php/features/TestFacet.php +++ b/tests/php/features/TestFacet.php @@ -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 ); } /**