Ticket #29839: taxonomy-20141113_01.diff
File taxonomy-20141113_01.diff, 2.6 KB (added by , 11 years ago) |
---|
-
taxonomy.php
1640 1640 1641 1641 $defaults = array('orderby' => 'name', 'order' => 'ASC', 1642 1642 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 1643 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 1643 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'children_only' => '', 1644 1644 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', 1645 1645 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); 1646 1646 $args = wp_parse_args( $args, $defaults ); … … 1653 1653 $args['pad_counts'] = false; 1654 1654 } 1655 1655 1656 // 'parent' overrides 'child_of' .1656 // 'parent' overrides 'child_of' 1657 1657 if ( 0 < intval( $args['parent'] ) ) { 1658 1658 $args['child_of'] = false; 1659 1659 } 1660 1660 1661 1661 if ( 'all' == $args['get'] ) { 1662 $args['children_only'] = 0; 1662 1663 $args['child_of'] = 0; 1663 1664 $args['hide_empty'] = 0; 1664 1665 $args['hierarchical'] = false; … … 1691 1692 } 1692 1693 } 1693 1694 1695 // Check for heirarchical taxonomy 1696 $children_only = $args['children_only']; // boolean 1697 if ( $children_only ) { 1698 // Empty if taxonomy is not heirarchical; term ids if it is. 1699 // Note that we are not checking for a specific child or parent, just the 1700 // existence of an heirarchical taxonomy 1701 $hierarchy = _get_term_hierarchy( reset( $taxonomies ) ); 1702 if ( empty( $hierarchy )) { 1703 return $empty_array; 1704 } 1705 } 1706 1694 1707 // $args can be whatever, only use the args defined in defaults to compute the key 1695 1708 $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : ''; 1696 1709 $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $defaults ) ) ) . serialize( $taxonomies ) . $filter_key ); … … 1798 1811 } 1799 1812 } 1800 1813 1814 if ( $children_only ) { 1815 $terms_to_exclude = ""; 1816 $term_heirarchy = _get_term_hierarchy( reset( $taxonomies ) ); 1817 if ( ! empty( $term_heirarchy ) ) { 1818 // Any term listed in $term_heirarchy has by definition a child term, so exclude it 1819 foreach ( array_keys($term_heirarchy) as $excluded_index=>$excluded_id ) { 1820 if ( empty($terms_to_exclude) ) { 1821 $terms_to_exclude = $excluded_id; 1822 } else { 1823 $terms_to_exclude .= ', ' . $excluded_id; 1824 } 1825 } 1826 } 1827 if ( empty( $exclusions ) ) { 1828 $exclusions = $terms_to_exclude; 1829 } else { 1830 $exclusions .= ', ' . $terms_to_exclude; 1831 } 1832 } 1833 1801 1834 if ( ! empty( $exclusions ) ) { 1802 1835 $exclusions = ' AND t.term_id NOT IN (' . $exclusions . ')'; 1803 1836 }