WordPress.org

Make WordPress Core

Changeset 14133


Ignore:
Timestamp:
04/18/2010 04:54:19 AM (8 years ago)
Author:
nacin
Message:

Allow include/exclude args to be arrays in get_posts() and get_pages(). Utilizes wp_parse_id_list(). props scribu, fixes #11076.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r14122 r14133  
    995995        'numberposts' => 5, 'offset' => 0,
    996996        'category' => 0, 'orderby' => 'post_date',
    997         'order' => 'DESC', 'include' => '',
    998         'exclude' => '', 'meta_key' => '',
     997        'order' => 'DESC', 'include' => array(),
     998        'exclude' => array(), 'meta_key' => '',
    999999        'meta_value' =>'', 'post_type' => 'post',
    10001000        'suppress_filters' => true
     
    10091009        $r['cat'] = $r['category'];
    10101010    if ( ! empty($r['include']) ) {
    1011         $incposts = preg_split('/[\s,]+/', $r['include']);
     1011        $incposts = wp_parse_id_list( $r['include'] );
    10121012        $r['posts_per_page'] = count($incposts);  // only the number of posts included
    10131013        $r['post__in'] = $incposts;
    10141014    } elseif ( ! empty($r['exclude']) )
    1015         $r['post__not_in'] = preg_split('/[\s,]+/',$r['exclude']);
     1015        $r['post__not_in'] = wp_parse_id_list( $r['exclude'] );
    10161016
    10171017    $r['caller_get_posts'] = true;
     
    29352935        'child_of' => 0, 'sort_order' => 'ASC',
    29362936        'sort_column' => 'post_title', 'hierarchical' => 1,
    2937         'exclude' => '', 'include' => '',
     2937        'exclude' => array(), 'include' => array(),
    29382938        'meta_key' => '', 'meta_value' => '',
    29392939        'authors' => '', 'parent' => -1, 'exclude_tree' => '',
     
    29762976        $meta_value = '';
    29772977        $hierarchical = false;
    2978         $incpages = preg_split('/[\s,]+/',$include);
    2979         if ( count($incpages) ) {
     2978        $incpages = wp_parse_id_list( $include );
     2979        if ( ! empty( $incpages ) ) {
    29802980            foreach ( $incpages as $incpage ) {
    29812981                if (empty($inclusions))
     
    29912991    $exclusions = '';
    29922992    if ( !empty($exclude) ) {
    2993         $expages = preg_split('/[\s,]+/',$exclude);
    2994         if ( count($expages) ) {
     2993        $expages = wp_parse_id_list( $exclude );
     2994        if ( ! empty( $expages ) ) {
    29952995            foreach ( $expages as $expage ) {
    29962996                if (empty($exclusions))
     
    30083008        $post_authors = preg_split('/[\s,]+/',$authors);
    30093009
    3010         if ( count($post_authors) ) {
     3010        if ( ! empty( $post_authors ) ) {
    30113011            foreach ( $post_authors as $post_author ) {
    30123012                //Do we have an author id or an author login?
Note: See TracChangeset for help on using the changeset viewer.