Ticket #29839: taxonomy.diff
File taxonomy.diff, 2.9 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'.1657 if ( 0 < intval( $args['parent'] ) ) {1656 // 'parent' and 'children_only' override 'child_of' 1657 if ( 0 < intval( $args['parent'] ) || true === $args['children_only'] ) { 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 ); … … 1852 1865 $offset = $args['offset']; 1853 1866 1854 1867 // don't limit the query results when we have to descend the family tree 1855 if ( $number && ! $hierarchical && ! $child_of && '' === $parent ) {1868 if ( $number && ! $hierarchical && ! $child_of && '' === $parent && '' === $children_only) { 1856 1869 if ( $offset ) { 1857 1870 $limits = 'LIMIT ' . $offset . ',' . $number; 1858 1871 } else { … … 1950 1963 } 1951 1964 } 1952 1965 1966 if ( $children_only ) { 1967 $terms = array(); 1968 $term_heirarchy = _get_term_hierarchy( reset( $taxonomies ) ); 1969 if ( ! empty( $term_heirarchy ) ) { 1970 // Get all terms, then purge the non-child ones by testing for further child terms 1971 $all_terms = get_terms($taxonomies, array('hide_empty' => $args['hide_empty'])); 1972 foreach ( $all_terms as $term ) { 1973 if ( ! $term_heirarchy[$term->term_id] ) { 1974 array_push( $terms, $term ); 1975 } 1976 } 1977 } 1978 } 1979 1953 1980 // Update term counts to include children. 1954 1981 if ( $args['pad_counts'] && 'all' == $_fields ) { 1955 1982 _pad_term_counts( $terms, reset( $taxonomies ) );