Make WordPress Core

Changeset 10275


Ignore:
Timestamp:
12/30/2008 10:30:36 PM (16 years ago)
Author:
ryan
Message:

Add exclude_tree for categories. Make exclude behave like exclude_tree when hierarchical to restore < 2.7 behavior. Props filosofo. fixes #8614 for trunk

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r10246 r10275  
    446446 *     'child_of' (int) default is 0 - See {@link get_categories()}.
    447447 *     'exclude' (string) - See {@link get_categories()}.
     448 *     'exclude_tree' (string) - See {@link get_categories()}.
    448449 *     'echo' (bool|int) default is 1 - Whether to display or retrieve content.
    449450 *     'current_category' (int) - See {@link get_categories()}.
     
    464465        'hide_empty' => 1, 'use_desc_for_title' => 1,
    465466        'child_of' => 0, 'feed' => '', 'feed_type' => '',
    466         'feed_image' => '', 'exclude' => '', 'current_category' => 0,
     467        'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0,
    467468        'hierarchical' => true, 'title_li' => __( 'Categories' ),
    468469        'echo' => 1, 'depth' => 0
     
    477478    if ( isset( $r['show_date'] ) ) {
    478479        $r['include_last_update_time'] = $r['show_date'];
     480    }
     481
     482    if ( true == $r['hierarchical'] ) {
     483        $r['exclude_tree'] = $r['exclude'];
     484        $r['exclude'] = '';
    479485    }
    480486
  • trunk/wp-includes/taxonomy.php

    r10222 r10275  
    535535 * 'exclude' is ignored.
    536536 *
     537 * exclude_tree - A comma- or space-delimited string of term ids to exclude
     538 * from the return array, along with all of their descendant terms according to
     539 * the primary taxonomy.  If 'include' is non-empty, 'exclude_tree' is ignored.
     540 *
    537541 * include - Default is an empty string.  A comma- or space-delimited string
    538542 * of term ids to include in the return array.
     
    605609
    606610    $defaults = array('orderby' => 'name', 'order' => 'ASC',
    607         'hide_empty' => true, 'exclude' => '', 'include' => '',
     611        'hide_empty' => true, 'exclude' => '', 'exclude_tree' => '', 'include' => '',
    608612        'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
    609613        'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '',
     
    669673    if ( !empty($include) ) {
    670674        $exclude = '';
     675        $exclude_tree = '';
    671676        $interms = preg_split('/[\s,]+/',$include);
    672677        if ( count($interms) ) {
     
    685690
    686691    $exclusions = '';
     692    if ( ! empty( $exclude_tree ) ) {
     693        $excluded_trunks = preg_split('/[\s,]+/',$exclude_tree);
     694        foreach( (array) $excluded_trunks as $extrunk ) {
     695            $excluded_children = (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids'));   
     696            $excluded_children[] = $extrunk;
     697            foreach( (array) $excluded_children as $exterm ) {
     698                if ( empty($exclusions) )
     699                    $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
     700                else
     701                    $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' ';
     702
     703            }
     704        }
     705    }
    687706    if ( !empty($exclude) ) {
    688707        $exterms = preg_split('/[\s,]+/',$exclude);
    689708        if ( count($exterms) ) {
    690709            foreach ( (array) $exterms as $exterm ) {
    691                 if (empty($exclusions))
     710                if ( empty($exclusions) )
    692711                    $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
    693712                else
Note: See TracChangeset for help on using the changeset viewer.