From 2906ead23667bb10f1510d6a4e0152fb5a511ef9 Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Mon, 3 Jul 2023 19:57:58 +0500 Subject: [PATCH 1/2] Fix: Don't apply facet filter to query if filter value is empty --- includes/classes/Feature/Facets/Facets.php | 3 +++ tests/php/features/TestFacet.php | 6 ++++++ 2 files changed, 9 insertions(+) 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..57531fedb5 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 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 ); } /** From 7f0cfd4884336b2ec6e30c7de836d209d22672eb Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Mon, 3 Jul 2023 20:04:39 +0500 Subject: [PATCH 2/2] Minor change --- tests/php/features/TestFacet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/php/features/TestFacet.php b/tests/php/features/TestFacet.php index 57531fedb5..381ca387a7 100644 --- a/tests/php/features/TestFacet.php +++ b/tests/php/features/TestFacet.php @@ -106,7 +106,7 @@ public function testGetSelected() { $this->assertArrayHasKey( 'post_type', $selected ); $this->assertSame( 'posttype', $selected['post_type'] ); - // test when filter is empty + // 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'] );