WC_Shortcode_Products::set_attributes_query_args( array $query_args )
Set attributes query args.
Description Description
Parameters Parameters
- $query_args
-
(Required) Query args.
Source Source
File: includes/shortcodes/class-wc-shortcode-products.php
protected function set_attributes_query_args( &$query_args ) { if ( ! empty( $this->attributes['attribute'] ) || ! empty( $this->attributes['terms'] ) ) { $taxonomy = strstr( $this->attributes['attribute'], 'pa_' ) ? sanitize_title( $this->attributes['attribute'] ) : 'pa_' . sanitize_title( $this->attributes['attribute'] ); $terms = $this->attributes['terms'] ? array_map( 'sanitize_title', explode( ',', $this->attributes['terms'] ) ) : array(); $field = 'slug'; if ( $terms && is_numeric( $terms[0] ) ) { $field = 'term_id'; $terms = array_map( 'absint', $terms ); // Check numeric slugs. foreach ( $terms as $term ) { $the_term = get_term_by( 'slug', $term, $taxonomy ); if ( false !== $the_term ) { $terms[] = $the_term->term_id; } } } // If no terms were specified get all products that are in the attribute taxonomy. if ( ! $terms ) { $terms = get_terms( array( 'taxonomy' => $taxonomy, 'fields' => 'ids', ) ); $field = 'term_id'; } // We always need to search based on the slug as well, this is to accommodate numeric slugs. $query_args['tax_query'][] = array( 'taxonomy' => $taxonomy, 'terms' => $terms, 'field' => $field, 'operator' => $this->attributes['terms_operator'], ); } }
Changelog Changelog
Version | Description |
---|---|
3.2.0 | Introduced. |