Make WordPress Core


Ignore:
Timestamp:
03/21/2006 04:26:50 AM (21 years ago)
Author:
ryan
Message:

Add include param to get_posts(), get_categories(), get_pages(), and get_bookmarks(). Props MichaelH. fixes #2562

File:
1 edited

Legend:

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

    r3605 r3655  
    377377
    378378        $defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC',
    379                 'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1);
     379                'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, $exclude => '', $include => '');
    380380        $r = array_merge($defaults, $r);
    381         $r['orderby'] = "cat_" . $r['orderby'];
     381        $r['orderby'] = "cat_" . $r['orderby'];  // restricts order by to cat_ID and cat_name fields
    382382        extract($r);
    383383
    384         $exclusions = '';
    385         $having = '';
    386384        $where = 'cat_ID > 0';
     385        $inclusions = '';
     386        if ( !empty($include) ) {
     387                $child_of = 0; //ignore child_of and exclude params if using include
     388                $exclude = ''; 
     389                $incategories = preg_split('/[\s,]+/',$include);
     390                if ( count($incategories) ) {
     391                        foreach ( $incategories as $incat ) {
     392                                if (empty($inclusions))
     393                                        $inclusions = ' AND ( cat_ID = ' . intval($incat) . ' ';
     394                                else
     395                                        $inclusions .= ' OR cat_ID = ' . intval($incat) . ' ';
     396                        }
     397                }
     398        }
     399        if (!empty($inclusions))
     400                $inclusions .= ')';     
     401        $where .= $inclusions;
    387402
    388403        $exclusions = '';
    … …  
    391406                if ( count($excategories) ) {
    392407                        foreach ( $excategories as $excat ) {
    393                                 $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
    394                                 // TODO: Exclude children of excluded cats?
     408                                if (empty($exclusions))
     409                                        $exclusions = ' AND ( cat_ID <> ' . intval($excat) . ' ';
     410                                else
     411                                        $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
     412                                // TODO: Exclude children of excluded cats?   Note: children are getting excluded
    395413                        }
    396414                }
    397415        }
     416        if (!empty($exclusions))
     417                $exclusions .= ')';
    398418        $exclusions = apply_filters('list_cats_exclusions', $exclusions );
    399419        $where .= $exclusions;
    400420
     421        $having = '';
    401422        if ( $hide_empty ) {
    402423                if ( 'link' == $type )
Note: See TracChangeset for help on using the changeset viewer.