Add exclude_tree for categories. Make exclude behave like exclude_tree when hierarchical to restore < 2.7 behavior. Props filosofo. fixes #8614 for trunk
git-svn-id: http://svn.automattic.com/wordpress/trunk@10275 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a3becc9f3a
commit
d38dee6a4a
|
@ -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 );
|
||||
|
|
|
@ -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) . ' ';
|
||||
|
|
Loading…
Reference in New Issue