diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index fb8e45def..f06a236d8 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -445,6 +445,7 @@ function wp_dropdown_categories( $args = '' ) { * 'feed_image' - See {@link get_categories()}. * 'child_of' (int) default is 0 - See {@link get_categories()}. * 'exclude' (string) - See {@link get_categories()}. + * 'exclude_tree' (string) - See {@link get_categories()}. * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. * 'current_category' (int) - See {@link get_categories()}. * 'hierarchical' (bool) - See {@link get_categories()}. @@ -463,7 +464,7 @@ function wp_list_categories( $args = '' ) { 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', - 'feed_image' => '', 'exclude' => '', 'current_category' => 0, + 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __( 'Categories' ), 'echo' => 1, 'depth' => 0 ); @@ -478,6 +479,11 @@ function wp_list_categories( $args = '' ) { $r['include_last_update_time'] = $r['show_date']; } + if ( true == $r['hierarchical'] ) { + $r['exclude_tree'] = $r['exclude']; + $r['exclude'] = ''; + } + extract( $r ); $categories = get_categories( $r ); diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index d0b644e55..8e4977f00 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -534,6 +534,10 @@ function get_term_to_edit( $id, $taxonomy ) { * of term ids to exclude from the return array. If 'include' is non-empty, * 'exclude' is ignored. * + * exclude_tree - A comma- or space-delimited string of term ids to exclude + * from the return array, along with all of their descendant terms according to + * the primary taxonomy. If 'include' is non-empty, 'exclude_tree' is ignored. + * * include - Default is an empty string. A comma- or space-delimited string * of term ids to include in the return array. * @@ -604,7 +608,7 @@ function &get_terms($taxonomies, $args = '') { $in_taxonomies = "'" . implode("', '", $taxonomies) . "'"; $defaults = array('orderby' => 'name', 'order' => 'ASC', - 'hide_empty' => true, 'exclude' => '', 'include' => '', + 'hide_empty' => true, 'exclude' => '', 'exclude_tree' => '', 'include' => '', 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => ''); @@ -668,6 +672,7 @@ function &get_terms($taxonomies, $args = '') { $inclusions = ''; if ( !empty($include) ) { $exclude = ''; + $exclude_tree = ''; $interms = preg_split('/[\s,]+/',$include); if ( count($interms) ) { foreach ( (array) $interms as $interm ) { @@ -684,11 +689,25 @@ function &get_terms($taxonomies, $args = '') { $where .= $inclusions; $exclusions = ''; + if ( ! empty( $exclude_tree ) ) { + $excluded_trunks = preg_split('/[\s,]+/',$exclude_tree); + foreach( (array) $excluded_trunks as $extrunk ) { + $excluded_children = (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids')); + $excluded_children[] = $extrunk; + foreach( (array) $excluded_children as $exterm ) { + if ( empty($exclusions) ) + $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; + else + $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; + + } + } + } if ( !empty($exclude) ) { $exterms = preg_split('/[\s,]+/',$exclude); if ( count($exterms) ) { foreach ( (array) $exterms as $exterm ) { - if (empty($exclusions)) + if ( empty($exclusions) ) $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; else $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' ';