wp/wp-includes/class-wp-tax-query.php
changeset 19 3d72ae0968f4
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   234 	 *
   234 	 *
   235 	 * @since 3.1.0
   235 	 * @since 3.1.0
   236 	 *
   236 	 *
   237 	 * @param string $primary_table     Database table where the object being filtered is stored (eg wp_users).
   237 	 * @param string $primary_table     Database table where the object being filtered is stored (eg wp_users).
   238 	 * @param string $primary_id_column ID column for the filtered object in $primary_table.
   238 	 * @param string $primary_id_column ID column for the filtered object in $primary_table.
   239 	 * @return array {
   239 	 * @return string[] {
   240 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   240 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   241 	 *
   241 	 *
   242 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   242 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   243 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   243 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   244 	 * }
   244 	 * }
   256 	 * Called by the public WP_Tax_Query::get_sql(), this method
   256 	 * Called by the public WP_Tax_Query::get_sql(), this method
   257 	 * is abstracted out to maintain parity with the other Query classes.
   257 	 * is abstracted out to maintain parity with the other Query classes.
   258 	 *
   258 	 *
   259 	 * @since 4.1.0
   259 	 * @since 4.1.0
   260 	 *
   260 	 *
   261 	 * @return array {
   261 	 * @return string[] {
   262 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   262 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   263 	 *
   263 	 *
   264 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   264 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   265 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   265 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   266 	 * }
   266 	 * }
   289 	 * @since 4.1.0
   289 	 * @since 4.1.0
   290 	 *
   290 	 *
   291 	 * @param array $query Query to parse (passed by reference).
   291 	 * @param array $query Query to parse (passed by reference).
   292 	 * @param int   $depth Optional. Number of tree levels deep we currently are.
   292 	 * @param int   $depth Optional. Number of tree levels deep we currently are.
   293 	 *                     Used to calculate indentation. Default 0.
   293 	 *                     Used to calculate indentation. Default 0.
   294 	 * @return array {
   294 	 * @return string[] {
   295 	 *     Array containing JOIN and WHERE SQL clauses to append to a single query array.
   295 	 *     Array containing JOIN and WHERE SQL clauses to append to a single query array.
   296 	 *
   296 	 *
   297 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   297 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   298 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   298 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   299 	 * }
   299 	 * }
   371 	 *
   371 	 *
   372 	 * @global wpdb $wpdb The WordPress database abstraction object.
   372 	 * @global wpdb $wpdb The WordPress database abstraction object.
   373 	 *
   373 	 *
   374 	 * @param array $clause       Query clause (passed by reference).
   374 	 * @param array $clause       Query clause (passed by reference).
   375 	 * @param array $parent_query Parent query array.
   375 	 * @param array $parent_query Parent query array.
   376 	 * @return array {
   376 	 * @return string[] {
   377 	 *     Array containing JOIN and WHERE SQL clauses to append to a first-order query.
   377 	 *     Array containing JOIN and WHERE SQL clauses to append to a first-order query.
   378 	 *
   378 	 *
   379 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   379 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   380 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   380 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   381 	 * }
   381 	 * }
   525 				continue;
   525 				continue;
   526 			}
   526 			}
   527 
   527 
   528 			// The sibling must both have compatible operator to share its alias.
   528 			// The sibling must both have compatible operator to share its alias.
   529 			if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators, true ) ) {
   529 			if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators, true ) ) {
   530 				$alias = $sibling['alias'];
   530 				$alias = preg_replace( '/\W/', '_', $sibling['alias'] );
   531 				break;
   531 				break;
   532 			}
   532 			}
   533 		}
   533 		}
   534 
   534 
   535 		return $alias;
   535 		return $alias;
   554 		} elseif ( ! taxonomy_exists( $query['taxonomy'] ) ) {
   554 		} elseif ( ! taxonomy_exists( $query['taxonomy'] ) ) {
   555 			$query = new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
   555 			$query = new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
   556 			return;
   556 			return;
   557 		}
   557 		}
   558 
   558 
   559 		$query['terms'] = array_unique( (array) $query['terms'] );
   559 		if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
       
   560 			$query['terms'] = array_unique( (array) $query['terms'] );
       
   561 		} else {
       
   562 			$query['terms'] = wp_parse_id_list( $query['terms'] );
       
   563 		}
   560 
   564 
   561 		if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
   565 		if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
   562 			$this->transform_query( $query, 'term_id' );
   566 			$this->transform_query( $query, 'term_id' );
   563 
   567 
   564 			if ( is_wp_error( $query ) ) {
   568 			if ( is_wp_error( $query ) ) {
   631 			default:
   635 			default:
   632 				$args['include'] = wp_parse_id_list( $terms );
   636 				$args['include'] = wp_parse_id_list( $terms );
   633 				break;
   637 				break;
   634 		}
   638 		}
   635 
   639 
       
   640 		if ( ! is_taxonomy_hierarchical( $query['taxonomy'] ) ) {
       
   641 			$args['number'] = count( $terms );
       
   642 		}
       
   643 
   636 		$term_query = new WP_Term_Query();
   644 		$term_query = new WP_Term_Query();
   637 		$term_list  = $term_query->query( $args );
   645 		$term_list  = $term_query->query( $args );
   638 
   646 
   639 		if ( is_wp_error( $term_list ) ) {
   647 		if ( is_wp_error( $term_list ) ) {
   640 			$query = $term_list;
   648 			$query = $term_list;