value_resolver = $term_value_resolver; } /** * @return array */ public function build_term_query( Term_Settings $term ): array { $is_value_comparison = ! in_array( $term->get_comparison(), self::NO_VALUE_COMPARISONS, true ); $term_value = $is_value_comparison ? $this->value_resolver->resolve_term_value( $term ) : null; $arguments = array( 'taxonomy' => array( 'value' => $term->get_taxonomy(), ), 'operator' => array( 'value' => $term->get_comparison(), ), 'field' => array( 'value' => fn() => $this->get_query_field( $term_value ), ), 'terms' => array( 'condition' => $is_value_comparison, 'value' => $term_value, ), ); return Query_Utils::filter_arguments( $arguments ); } /** * @param null|mixed[] $term_value */ private function get_query_field( ?array $term_value ): string { $first_item = any( $term_value, 0 ); // prefer id to slug - as WordPress has a slug-related bug. if ( is_null( $first_item ) || is_numeric( $first_item ) ) { return 'term_id'; } return 'slug'; } }