Make WordPress Core

Ticket #21309: stickies-get_posts.diff

File stickies-get_posts.diff, 1.4 KB (added by scribu, 13 years ago)
  • wp-includes/query.php

    diff --git wp-includes/query.php wp-includes/query.php
    index e249ec2..8d85e3e 100644
    class WP_Query { 
    27332733
    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                                 }
     2736                                $stickies = get_posts( array(
     2737                                        'post__in' => $sticky_posts,
     2738                                        'post_type' => $post_type,
     2739                                        'post_status' => 'publish',
     2740                                        'nopaging' => true
     2741                                ) );
    27472742
    2748                                 $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" );
    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                                }
    27562747                        }