Ticket #11076: get_terms.4.diff
File get_terms.4.diff, 5.0 KB (added by , 15 years ago) |
---|
-
wp-includes/taxonomy.php
571 571 * hide_empty - Default is true. Will not return empty terms, which means 572 572 * terms whose count is 0 according to the given taxonomy. 573 573 * 574 * exclude - Default is an empty string. Acomma- or space-delimited string574 * exclude - Default is an empty array. An array, comma- or space-delimited string 575 575 * of term ids to exclude from the return array. If 'include' is non-empty, 576 576 * 'exclude' is ignored. 577 577 * 578 * exclude_tree - A comma- or space-delimited string of term ids to exclude 579 * from the return array, along with all of their descendant terms according to 580 * the primary taxonomy. If 'include' is non-empty, 'exclude_tree' is ignored. 578 * exclude_tree - Default is an empty array. An array, comma- or space-delimited 579 * string of term ids to exclude from the return array, along with all of their 580 * descendant terms according to the primary taxonomy. If 'include' is non-empty, 581 * 'exclude_tree' is ignored. 581 582 * 582 * include - Default is an empty string. Acomma- or space-delimited string583 * include - Default is an empty array. An array, comma- or space-delimited string 583 584 * of term ids to include in the return array. 584 585 * 585 * number - The maximum number of terms to return. Default is empty .586 * number - The maximum number of terms to return. Default is empty string. 586 587 * 587 588 * offset - The number by which to offset the terms query. 588 589 * … … 651 652 $in_taxonomies = "'" . implode("', '", $taxonomies) . "'"; 652 653 653 654 $defaults = array('orderby' => 'name', 'order' => 'ASC', 654 'hide_empty' => true, 'exclude' => '', 'exclude_tree' => '', 'include' => '',655 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 655 656 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 656 657 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 657 658 'pad_counts' => false, 'offset' => '', 'search' => ''); … … 719 720 if ( !empty($include) ) { 720 721 $exclude = ''; 721 722 $exclude_tree = ''; 722 $interms = preg_split('/[\s,]+/',$include); 723 if ( count($interms) ) { 724 foreach ( (array) $interms as $interm ) { 725 if (empty($inclusions)) 726 $inclusions = ' AND ( t.term_id = ' . intval($interm) . ' '; 727 else 728 $inclusions .= ' OR t.term_id = ' . intval($interm) . ' '; 729 } 723 $interms = wp_parse_id_list($include); 724 foreach ( $interms as $interm ) { 725 if ( empty($inclusions) ) 726 $inclusions = ' AND ( t.term_id = ' . intval($interm) . ' '; 727 else 728 $inclusions .= ' OR t.term_id = ' . intval($interm) . ' '; 730 729 } 731 730 } 732 731 … … 735 734 $where .= $inclusions; 736 735 737 736 $exclusions = ''; 738 if ( ! 739 $excluded_trunks = preg_split('/[\s,]+/',$exclude_tree);740 foreach ( (array)$excluded_trunks as $extrunk ) {737 if ( !empty( $exclude_tree ) ) { 738 $excluded_trunks = wp_parse_id_list($exclude_tree); 739 foreach ( $excluded_trunks as $extrunk ) { 741 740 $excluded_children = (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids')); 742 741 $excluded_children[] = $extrunk; 743 foreach( (array)$excluded_children as $exterm ) {742 foreach( $excluded_children as $exterm ) { 744 743 if ( empty($exclusions) ) 745 744 $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; 746 745 else 747 746 $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; 748 749 747 } 750 748 } 751 749 } 750 752 751 if ( !empty($exclude) ) { 753 $exterms = preg_split('/[\s,]+/',$exclude); 754 if ( count($exterms) ) { 755 foreach ( (array) $exterms as $exterm ) { 756 if ( empty($exclusions) ) 757 $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; 758 else 759 $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; 760 } 752 $exterms = wp_parse_id_list($exclude); 753 foreach ( $exterms as $exterm ) { 754 if ( empty($exclusions) ) 755 $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; 756 else 757 $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; 761 758 } 762 759 } 763 760 … … 834 831 foreach ( $terms as $k => $term ) { 835 832 if ( ! $term->count ) { 836 833 $children = _get_term_children($term->term_id, $terms, $taxonomies[0]); 837 if ( is_array($children) )834 if ( is_array($children) ) 838 835 foreach ( $children as $child ) 839 836 if ( $child->count ) 840 837 continue 2; -
wp-includes/functions.php
2787 2787 } 2788 2788 2789 2789 /** 2790 * Clean up an array, comma- or space-separated list of IDs 2791 * 2792 * @since 3.0.0 2793 * 2794 * @param array|string $list 2795 * @return array 2796 */ 2797 function wp_parse_id_list($list) { 2798 if ( !is_array($list) ) 2799 $list = preg_split('/[\s,]+/', $list); 2800 2801 return array_unique(array_map('absint', $list)); 2802 } 2803 2804 /** 2790 2805 * Determines if default embed handlers should be loaded. 2791 2806 * 2792 2807 * Checks to make sure that the embeds library hasn't already been loaded. If