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-bookmarks.php

    r3606 r3655  
    284284
    285285        $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => -1,
    286                 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0);
     286                'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '');
    287287        $r = array_merge($defaults, $r);
    288288        extract($r);
    289289
     290        $inclusions = '';
     291        if ( !empty($include) ) {
     292        $exclude = '';  //ignore exclude, category, and category_name params if using include
     293        $category = -1;
     294        $category_name = '';
     295                $inclinks = preg_split('/[\s,]+/',$include);
     296                if ( count($inclinks) ) {
     297                        foreach ( $inclinks as $inclink ) {
     298                                if (empty($inclusions))
     299                                        $inclusions = ' AND ( link_id = ' . intval($inclink) . ' ';
     300                                else
     301                                        $inclusions .= ' OR link_id = ' . intval($inclink) . ' ';
     302                        }
     303                }
     304        }
     305        if (!empty($inclusions))
     306                $inclusions .= ')';
     307
    290308        $exclusions = '';
    291309        if ( !empty($exclude) ) {
    292                 $exlinks = preg_split('/[\s,]+/',$r['exclude']);
     310                $exlinks = preg_split('/[\s,]+/',$exclude);
    293311                if ( count($exlinks) ) {
    294312                        foreach ( $exlinks as $exlink ) {
    295                                 $exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';
     313                                if (empty($exclusions))
     314                                        $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' ';
     315                                else
     316                                        $exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';
    296317                        }
    297318                }
    298319        }
    299 
     320        if (!empty($exclusions))
     321                $exclusions .= ')';
     322               
    300323        if ( ! empty($category_name) ) {
    301324                if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") )
    … …  
    321344        }
    322345
    323         $orderby = strtolower($r['orderby']);
     346        $orderby = strtolower($orderby);
    324347        $length = '';
    325348        switch ($orderby) {
    … …  
    342365
    343366        $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query";
     367        $query .= " $exclusions $inclusions";
    344368        $query .= " ORDER BY $orderby $order";
    345369        if ($limit != -1)
Note: See TracChangeset for help on using the changeset viewer.