Ticket #11076: get_terms.3.diff
File get_terms.3.diff, 4.6 KB (added by scribu, 5 years ago) 


wpincludes/taxonomy.php
545 545 * hide_empty  Default is true. Will not return empty terms, which means 546 546 * terms whose count is 0 according to the given taxonomy. 547 547 * 548 * exclude  Default is an empty string. Acomma or spacedelimited string548 * exclude  Default is an empty array. An array, comma or spacedelimited string 549 549 * of term ids to exclude from the return array. If 'include' is nonempty, 550 550 * 'exclude' is ignored. 551 551 * 552 * exclude_tree  A comma or spacedelimited string of term ids to exclude 553 * from the return array, along with all of their descendant terms according to 554 * the primary taxonomy. If 'include' is nonempty, 'exclude_tree' is ignored. 552 * exclude_tree  Default is an empty array. An array, comma or spacedelimited 553 * string of term ids to exclude from the return array, along with all of their 554 * descendant terms according to the primary taxonomy. If 'include' is nonempty, 555 * 'exclude_tree' is ignored. 555 556 * 556 * include  Default is an empty string. Acomma or spacedelimited string557 * include  Default is an empty array. An array, comma or spacedelimited string 557 558 * of term ids to include in the return array. 558 559 * 559 * number  The maximum number of terms to return. Default is empty .560 * number  The maximum number of terms to return. Default is empty string. 560 561 * 561 562 * offset  The number by which to offset the terms query. 562 563 * … … 625 626 $in_taxonomies = "'" . implode("', '", $taxonomies) . "'"; 626 627 627 628 $defaults = array('orderby' => 'name', 'order' => 'ASC', 628 'hide_empty' => true, 'exclude' => '', 'exclude_tree' => '', 'include' => '',629 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 629 630 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 630 631 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 631 632 'pad_counts' => false, 'offset' => '', 'search' => ''); … … 693 694 if ( !empty($include) ) { 694 695 $exclude = ''; 695 696 $exclude_tree = ''; 696 $interms = preg_split('/[\s,]+/',$include); 697 if ( count($interms) ) { 698 foreach ( (array) $interms as $interm ) { 699 if (empty($inclusions)) 700 $inclusions = ' AND ( t.term_id = ' . intval($interm) . ' '; 701 else 702 $inclusions .= ' OR t.term_id = ' . intval($interm) . ' '; 703 } 697 $interms = _parse_get_terms_arg($include); 698 foreach ( $interms as $interm ) { 699 if ( empty($inclusions) ) 700 $inclusions = ' AND ( t.term_id = ' . intval($interm) . ' '; 701 else 702 $inclusions .= ' OR t.term_id = ' . intval($interm) . ' '; 704 703 } 705 704 } 706 705 … … 709 708 $where .= $inclusions; 710 709 711 710 $exclusions = ''; 712 if ( ! 713 $excluded_trunks = preg_split('/[\s,]+/',$exclude_tree);714 foreach ( (array)$excluded_trunks as $extrunk ) {711 if ( !empty( $exclude_tree ) ) { 712 $excluded_trunks = _parse_get_terms_arg($exclude_tree); 713 foreach ( $excluded_trunks as $extrunk ) { 715 714 $excluded_children = (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids')); 716 715 $excluded_children[] = $extrunk; 717 foreach( (array)$excluded_children as $exterm ) {716 foreach( $excluded_children as $exterm ) { 718 717 if ( empty($exclusions) ) 719 718 $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; 720 719 else 721 720 $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; 722 723 721 } 724 722 } 725 723 } 724 726 725 if ( !empty($exclude) ) { 727 $exterms = preg_split('/[\s,]+/',$exclude); 728 if ( count($exterms) ) { 729 foreach ( (array) $exterms as $exterm ) { 730 if ( empty($exclusions) ) 731 $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; 732 else 733 $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; 734 } 726 $exterms = _parse_get_terms_arg($exclude); 727 foreach ( $exterms as $exterm ) { 728 if ( empty($exclusions) ) 729 $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; 730 else 731 $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; 735 732 } 736 733 } 737 734 … … 808 805 foreach ( $terms as $k => $term ) { 809 806 if ( ! $term>count ) { 810 807 $children = _get_term_children($term>term_id, $terms, $taxonomies[0]); 811 if ( is_array($children) )808 if ( is_array($children) ) 812 809 foreach ( $children as $child ) 813 810 if ( $child>count ) 814 811 continue 2; … … 841 838 return $terms; 842 839 } 843 840 841 function _parse_get_terms_arg($arg) { 842 if ( is_array($arg) ) 843 return array_unique($arg); 844 845 return array_unique(preg_split('/[\s,]+/', $arg)); 846 } 847 844 848 /** 845 849 * Check if Term exists. 846 850 *