Changes from branches/3.1/wp-includes/taxonomy.php at r18021 to trunk/wp-includes/taxonomy.php at r18254
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/taxonomy.php
r18021 r18254 37 37 'rewrite' => did_action( 'init' ) ? array( 38 38 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag', 39 'with_front' => ( get_option(' category_base') && ! $wp_rewrite->using_index_permalinks() ) ? false : true ) : false,39 'with_front' => ( get_option('tag_base') && ! $wp_rewrite->using_index_permalinks() ) ? false : true ) : false, 40 40 'public' => true, 41 41 'show_ui' => true, … … 355 355 356 356 $args['name'] = $taxonomy; 357 $args['object_type'] = (array) $object_type;357 $args['object_type'] = array_unique( (array)$object_type ); 358 358 359 359 $args['labels'] = get_taxonomy_labels( (object) $args ); … … 405 405 'parent_item_colon' => array( null, __( 'Parent Category:' ) ), 406 406 'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ), 407 'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ), 407 408 'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ), 408 409 'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ), … … 438 439 return false; 439 440 440 $wp_taxonomies[$taxonomy]->object_type[] = $object_type; 441 if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) ) 442 $wp_taxonomies[$taxonomy]->object_type[] = $object_type; 441 443 442 444 return true; … … 540 542 * Default: 'term_id' 541 543 * - 'operator' string (optional) 542 * Possible values: ' IN' and'NOT IN'.544 * Possible values: 'AND', 'IN' or 'NOT IN'. 543 545 * Default: 'IN' 544 546 * - 'include_children' bool (optional) Whether to include child terms. … … 549 551 * @var array 550 552 */ 551 var$queries = array();553 public $queries = array(); 552 554 553 555 /** … … 558 560 * @var string 559 561 */ 560 var$relation;562 public $relation; 561 563 562 564 /** 563 * PHP4 type constructor. 565 * Standard response when the query should not return any rows. 566 * 567 * @since 3.2.0 568 * @access private 569 * @var string 570 */ 571 private static $no_results = array( 'join' => '', 'where' => ' AND 0 = 1' ); 572 573 /** 574 * Constructor. 564 575 * 565 576 * Parses a compact tax query and sets defaults. … … 582 593 * ), 583 594 * ) 584 *585 * @return WP_Tax_Query586 595 */ 587 function WP_Tax_Query( $tax_query ) {596 public function __construct( $tax_query ) { 588 597 if ( isset( $tax_query['relation'] ) && strtoupper( $tax_query['relation'] ) == 'OR' ) { 589 598 $this->relation = 'OR'; … … 622 631 * @return array 623 632 */ 624 function get_sql( $primary_table, $primary_id_column ) {633 public function get_sql( $primary_table, $primary_id_column ) { 625 634 global $wpdb; 626 635 … … 630 639 631 640 foreach ( $this->queries as $query ) { 641 $this->clean_query( $query ); 642 643 if ( is_wp_error( $query ) ) { 644 return self::$no_results; 645 } 646 632 647 extract( $query ); 633 634 if ( ! taxonomy_exists( $taxonomy ) )635 return array( 'join' => '', 'where' => ' AND 0 = 1');636 637 $terms = array_unique( (array) $terms );638 639 if ( empty( $terms ) )640 continue;641 642 if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) {643 $this->_transform_terms( $terms, $taxonomy, $field, 'term_id' );644 645 $children = array();646 foreach ( $terms as $term ) {647 $children = array_merge( $children, get_term_children( $term, $taxonomy ) );648 $children[] = $term;649 }650 $terms = $children;651 652 $this->_transform_terms( $terms, $taxonomy, 'term_id', 'term_taxonomy_id' );653 }654 else {655 $this->_transform_terms( $terms, $taxonomy, $field, 'term_taxonomy_id' );656 }657 648 658 649 if ( 'IN' == $operator ) { … … 662 653 continue; 663 654 else 664 return array( 'join' => '', 'where' => ' AND 0 = 1' );655 return self::$no_results; 665 656 } 666 657 … … 695 686 $terms = implode( ',', $terms ); 696 687 697 $where[] = " $primary_table.$primary_id_column IN(698 SELECT object_id688 $where[] = "( 689 SELECT COUNT(1) 699 690 FROM $wpdb->term_relationships 700 691 WHERE term_taxonomy_id IN ($terms) 701 GROUP BY object_id HAVING COUNT(object_id) = $num_terms702 ) ";692 AND object_id = $primary_table.$primary_id_column 693 ) = $num_terms"; 703 694 } 704 695 … … 715 706 716 707 /** 717 * Transforms a list of terms, from one field to another.708 * Validates a single query. 718 709 * 719 * @since 3. 1.0710 * @since 3.2.0 720 711 * @access private 721 712 * 722 * @param array &$terms The list of terms 723 * @param string $taxonomy The taxonomy of the terms 724 * @param string $field The initial field 713 * @param array &$query The single query 714 */ 715 private function clean_query( &$query ) { 716 if ( ! taxonomy_exists( $query['taxonomy'] ) ) { 717 $query = new WP_Error( 'Invalid taxonomy' ); 718 return; 719 } 720 721 $query['terms'] = array_unique( (array) $query['terms'] ); 722 723 if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) { 724 $this->transform_query( $query, 'term_id' ); 725 726 if ( is_wp_error( $query ) ) 727 return; 728 729 $children = array(); 730 foreach ( $query['terms'] as $term ) { 731 $children = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) ); 732 $children[] = $term; 733 } 734 $query['terms'] = $children; 735 } 736 737 $this->transform_query( $query, 'term_taxonomy_id' ); 738 } 739 740 /** 741 * Transforms a single query, from one field to another. 742 * 743 * @since 3.2.0 744 * @access private 745 * 746 * @param array &$query The single query 725 747 * @param string $resulting_field The resulting field 726 748 */ 727 function _transform_terms( &$terms, $taxonomy, $field, $resulting_field ) {749 private function transform_query( &$query, $resulting_field ) { 728 750 global $wpdb; 729 751 730 if ( empty( $ terms) )752 if ( empty( $query['terms'] ) ) 731 753 return; 732 754 733 if ( $ field== $resulting_field )755 if ( $query['field'] == $resulting_field ) 734 756 return; 735 757 736 758 $resulting_field = esc_sql( $resulting_field ); 737 759 738 switch ( $ field) {760 switch ( $query['field'] ) { 739 761 case 'slug': 740 762 case 'name': 741 $terms = "'" . implode( "','", array_map( 'sanitize_title_for_query', $ terms) ) . "'";763 $terms = "'" . implode( "','", array_map( 'sanitize_title_for_query', $query['terms'] ) ) . "'"; 742 764 $terms = $wpdb->get_col( " 743 765 SELECT $wpdb->term_taxonomy.$resulting_field 744 766 FROM $wpdb->term_taxonomy 745 767 INNER JOIN $wpdb->terms USING (term_id) 746 WHERE taxonomy = ' $taxonomy'747 AND $wpdb->terms. $fieldIN ($terms)768 WHERE taxonomy = '{$query['taxonomy']}' 769 AND $wpdb->terms.{$query['field']} IN ($terms) 748 770 " ); 749 771 break; 750 772 751 773 default: 752 $terms = implode( ',', array_map( 'intval', $ terms) );774 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 753 775 $terms = $wpdb->get_col( " 754 776 SELECT $resulting_field 755 777 FROM $wpdb->term_taxonomy 756 WHERE taxonomy = ' $taxonomy'778 WHERE taxonomy = '{$query['taxonomy']}' 757 779 AND term_id IN ($terms) 758 780 " ); 759 781 } 782 783 if ( 'AND' == $query['operator'] && count( $terms ) < count( $query['terms'] ) ) { 784 $query = new WP_Error( 'Inexistent terms' ); 785 return; 786 } 787 788 $query['terms'] = $terms; 789 $query['field'] = $resulting_field; 760 790 } 761 791 } … … 1101 1131 * of term Y only if term X is the father of term Y, not its grandfather or great-grandfather, etc. 1102 1132 * 1133 * The 'cache_domain' argument enables a unique cache key to be produced when this query is stored 1134 * in object cache. For instance, if you are using one of this function's filters to modify the 1135 * query (such as 'terms_clauses'), setting 'cache_domain' to a unique value will not overwrite 1136 * the cache for similar queries. Default value is 'core'. 1137 * 1103 1138 * @package WordPress 1104 1139 * @subpackage Taxonomy … … 1133 1168 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 1134 1169 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 1135 'pad_counts' => false, 'offset' => '', 'search' => '' );1170 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); 1136 1171 $args = wp_parse_args( $args, $defaults ); 1137 1172 $args['number'] = absint( $args['number'] );
Note: See TracChangeset
for help on using the changeset viewer.