Ticket #29839: 20141115_02-taxonomy.diff
File 20141115_02-taxonomy.diff, 3.2 KB (added by , 11 years ago) |
---|
-
src/wp-includes/taxonomy.php
1616 1616 * @type int $child_of Term ID to retrieve child terms of. If multiple taxonomies 1617 1617 * are passed, $child_of is ignored. Default 0. 1618 1618 * @type int|string $parent Parent term ID to retrieve direct-child terms of. Default empty. 1619 * @type bool $childless_terms The opposite of parent: returns terms that have no children. 1620 * Null if taxonomy is not hierarchical. Default false 1619 1621 * @type string $cache_domain Unique cache key to be produced when this query is stored in an 1620 1622 * object cache. Default is 'core'. 1621 1623 * } … … 1640 1642 1641 1643 $defaults = array('orderby' => 'name', 'order' => 'ASC', 1642 1644 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 1643 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 1645 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'childless_terms' => false, 1644 1646 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', 1645 1647 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); 1646 1648 $args = wp_parse_args( $args, $defaults ); … … 1659 1661 } 1660 1662 1661 1663 if ( 'all' == $args['get'] ) { 1664 $args['childless_terms'] = 0; 1662 1665 $args['child_of'] = 0; 1663 1666 $args['hide_empty'] = 0; 1664 1667 $args['hierarchical'] = false; … … 1691 1694 } 1692 1695 } 1693 1696 1697 // Check for heirarchical taxonomy 1698 $childless_terms = $args['childless_terms']; // boolean 1699 if ( $childless_terms ) { 1700 // Empty if taxonomy is not heirarchical; term ids if it is. 1701 // Note that we are not checking for a specific child or parent, just the 1702 // existence of an heirarchical taxonomy 1703 $hierarchy = _get_term_hierarchy( reset( $taxonomies ) ); 1704 if ( empty( $hierarchy )) { 1705 return $empty_array; 1706 } 1707 } 1708 1694 1709 // $args can be whatever, only use the args defined in defaults to compute the key 1695 1710 $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : ''; 1696 1711 $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $defaults ) ) ) . serialize( $taxonomies ) . $filter_key ); … … 1798 1813 } 1799 1814 } 1800 1815 1816 if ( $childless_terms ) { 1817 $terms_to_exclude = ""; 1818 $term_heirarchy = _get_term_hierarchy( reset( $taxonomies ) ); 1819 if ( ! empty( $term_heirarchy ) ) { 1820 // Any term listed in $term_heirarchy has by definition a child term, so exclude it 1821 foreach ( array_keys($term_heirarchy) as $excluded_index=>$excluded_id ) { 1822 if ( empty($terms_to_exclude) ) { 1823 $terms_to_exclude = $excluded_id; 1824 } else { 1825 $terms_to_exclude .= ', ' . $excluded_id; 1826 } 1827 } 1828 } 1829 if ( empty( $exclusions ) ) { 1830 $exclusions = $terms_to_exclude; 1831 } else { 1832 $exclusions .= ', ' . $terms_to_exclude; 1833 } 1834 } 1835 1801 1836 if ( ! empty( $exclusions ) ) { 1802 1837 $exclusions = ' AND t.term_id NOT IN (' . $exclusions . ')'; 1803 1838 }