Make WordPress Core

Changeset 21585


Ignore:
Timestamp:
08/22/2012 06:24:23 PM (13 years ago)
Author:
ryan
Message:

Use get_posts() to fetch stickies rather than custom bare SQL. Props scribu. see #21309

File:
1 edited

Legend:

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

    r21569 r21585  
    27342734            // Fetch sticky posts that weren't in the query results
    27352735            if ( !empty($sticky_posts) ) {
    2736                 $stickies__in = implode(',', array_map( 'absint', $sticky_posts ));
    2737                 // honor post type(s) if not set to any
    2738                 $stickies_where = '';
    2739                 if ( 'any' != $post_type && '' != $post_type ) {
    2740                     if ( is_array( $post_type ) ) {
    2741                         $post_types = join( "', '", $post_type );
    2742                     } else {
    2743                         $post_types = $post_type;
    2744                     }
    2745                     $stickies_where = "AND $wpdb->posts.post_type IN ('" . $post_types . "')";
    2746                 }
    2747 
    2748                 $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" );
     2736                $stickies = get_posts( array(
     2737                    'post__in' => $sticky_posts,
     2738                    'post_type' => $post_type,
     2739                    'post_status' => 'publish',
     2740                    'nopaging' => true
     2741                ) );
     2742
    27492743                foreach ( $stickies as $sticky_post ) {
    2750                     // Ignore sticky posts the current user cannot read or are not published.
    2751                     if ( 'publish' != $sticky_post->post_status )
    2752                         continue;
    2753                     array_splice($this->posts, $sticky_offset, 0, array( get_post( $sticky_post ) ) );
     2744                    array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
    27542745                    $sticky_offset++;
    27552746                }
Note: See TracChangeset for help on using the changeset viewer.