Skip to content

Commit bb03103

Browse files
authored
fix: Adds slight shim to give support for multiple category or tags by slug (#830)
* fix: regression in complex filtering by taxonomy slug fixed * chore: Linter and PHPStan compliance met
1 parent ca5dac0 commit bb03103

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

includes/data/connection/class-product-connection-resolver.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,25 @@ public function sanitize_input_fields( array $where_args ) {
368368
case 'tag':
369369
case 'tagIn':
370370
case 'tagNotIn':
371+
// Get terms.
372+
$terms = $where_args[ $field ];
373+
if ( ! is_array( $terms ) ) {
374+
$terms = [ $terms ];
375+
}
376+
377+
// Get term taxonomy IDs for complex tax queries.
378+
$term_taxonomy_ids = [];
379+
foreach ( $terms as $term_slug ) {
380+
$term = get_term_by( 'slug', $term_slug, $taxonomy );
381+
if ( ! $term || is_wp_error( $term ) ) {
382+
continue;
383+
}
384+
$term_taxonomy_ids[] = $term->term_taxonomy_id;
385+
}
371386
$tax_query[] = [
372387
'taxonomy' => $taxonomy,
373-
'field' => 'slug',
374-
'terms' => $where_args[ $field ],
388+
'field' => 'term_taxonomy_id',
389+
'terms' => $term_taxonomy_ids,
375390
'operator' => $operator,
376391
];
377392
break;

0 commit comments

Comments
 (0)