Make WordPress Core


Ignore:
Timestamp:
08/20/2015 02:18:05 AM (10 years ago)
Author:
boonebgorges
Message:

Introduce post_name__in parameter for WP_Query.

Props enshrined.
Fixes #33065.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r33095 r33653  
    14351435        }
    14361436
    1437         $array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
     1437        $array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'post_name__in',
    14381438            'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'post_parent__in', 'post_parent__not_in',
    14391439            'author__in', 'author__not_in' );
     
    14521452     * @since 4.2.0 Introduced the ability to order by specific clauses of a `$meta_query`, by passing the clause's
    14531453     *              array key to `$orderby`.
     1454     * @since 4.3.0 Introduced the `$post_name__in` parameter.
    14541455     * @access public
    14551456     *
     
    15281529     *     @type int          $posts_per_archive_page  The number of posts to query for by archive page. Overrides
    15291530     *                                                 'posts_per_page' when is_archive(), or is_search() are true.
     1531     *     @type array        $post_name__in           An array of post slugs that results must match.
    15301532     *     @type string       $s                       Search keyword.
    15311533     *     @type int          $second                  Second of the minute. Default empty. Accepts numbers 0-60.
     
    26042606        }
    26052607
     2608        // Parameters related to 'post_name'.
    26062609        if ( '' != $q['name'] ) {
    26072610            $q['name'] = sanitize_title_for_query( $q['name'] );
     
    26482651            $q['name'] = $q['attachment'];
    26492652            $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'";
    2650         }
    2651 
     2653        } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) {
     2654            $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] );
     2655            $where .= " AND $wpdb->posts.post_name IN ('" . implode( "' ,'", $q['post_name__in'] ) . "')";
     2656        }
    26522657
    26532658        if ( intval($q['comments_popup']) )
Note: See TracChangeset for help on using the changeset viewer.