From 3d5f9d8ff158b7a6f69f3277d1943a0f3a5b451b Mon Sep 17 00:00:00 2001 From: Paul Kevan <2290623+pkevan@users.noreply.github.com> Date: Thu, 9 May 2024 10:42:56 +0100 Subject: [PATCH 1/2] Update search.php Changes to query via slug, rather than term_id, since the new taxonomy `wporg-pattern-keyword` is used with slug. --- .../wp-content/plugins/pattern-directory/includes/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public_html/wp-content/plugins/pattern-directory/includes/search.php b/public_html/wp-content/plugins/pattern-directory/includes/search.php index 509eb2ad7..72b0f6b16 100644 --- a/public_html/wp-content/plugins/pattern-directory/includes/search.php +++ b/public_html/wp-content/plugins/pattern-directory/includes/search.php @@ -150,7 +150,7 @@ function modify_es_query_args( $es_query_args, $wp_query ) { } $filter['bool']['must'][] = [ - 'terms' => [ "taxonomy.$taxonomy.term_id" => $term['terms'] ], + 'term' => [ "$taxonomy.slug" => $term['terms'] ], ]; } } From 45cff9525c66c12638476b20bd9845dcca43b29b Mon Sep 17 00:00:00 2001 From: Paul Kevan <2290623+pkevan@users.noreply.github.com> Date: Tue, 14 May 2024 16:34:55 +0100 Subject: [PATCH 2/2] Update search.php Add switch for term_id and slug depending on input. --- .../plugins/pattern-directory/includes/search.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/public_html/wp-content/plugins/pattern-directory/includes/search.php b/public_html/wp-content/plugins/pattern-directory/includes/search.php index 72b0f6b16..608a6d1b9 100644 --- a/public_html/wp-content/plugins/pattern-directory/includes/search.php +++ b/public_html/wp-content/plugins/pattern-directory/includes/search.php @@ -148,10 +148,15 @@ function modify_es_query_args( $es_query_args, $wp_query ) { if ( ! in_array( $taxonomy, array( 'wporg-pattern-category', 'wporg-pattern-keyword' ) ) ) { continue; } - - $filter['bool']['must'][] = [ - 'term' => [ "$taxonomy.slug" => $term['terms'] ], - ]; + if ( is_string( $term['terms'] ) ) { + $filter['bool']['must'][] = [ + 'term' => [ "taxonomy.$taxonomy.slug" => $term['terms'] ], + ]; + } else if ( is_int( $term['terms'] ) ) { + $filter['bool']['must'][] = [ + 'term' => [ "taxonomy.$taxonomy.term_id" => $term['terms'] ], + ]; + } } }