Skip to content

Fix warning when the term entered doesn't exist. #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions includes/Traits/Tax_Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function process_tax_query() {
}

public function parse_tax_query( $queries ) {
$tax_query = [];
$tax_query = array();
// Don't process empty array of queries.
if ( isset( $queries['queries'] ) && count( $queries['queries'] ) > 0 ) {
// Handle the relation parameter.
Expand All @@ -24,7 +24,15 @@ public function parse_tax_query( $queries ) {
if ( isset( $query['taxonomy'] ) && isset( $query['terms'] ) && count( $query['terms'] ) > 0 ) {
$processed_query = array_filter( $query, fn( $key ) => 'id' !== $key, ARRAY_FILTER_USE_KEY );
$processed_query['include_children'] = filter_var( $query['include_children'], FILTER_VALIDATE_BOOLEAN );
$processed_query['terms'] = [ ...array_map( fn( $term ) => get_term_by( 'name', $term, $query['taxonomy'] )->term_id, $query['terms'] ) ];
$processed_query['terms'] = array_filter(
array_map(
function ( $term ) use ( $query ) {
$term_obj = get_term_by( 'name', $term, $query['taxonomy'] );
return $term_obj ? $term_obj->term_id : null;
},
$query['terms']
)
);
$tax_query[] = $processed_query;
}
}
Expand Down
Loading