Skip to content

Commit

Permalink
Use get_posts() to fetch stickies rather than custom bare SQL. Props …
Browse files Browse the repository at this point in the history
…scribu. see #21309

git-svn-id: http://core.svn.wordpress.org/trunk@21585 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
Ryan Boren committed Aug 22, 2012
1 parent 9f02c68 commit 7515511
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions wp-includes/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2733,24 +2733,15 @@ function &get_posts() {

// Fetch sticky posts that weren't in the query results
if ( !empty($sticky_posts) ) {
$stickies__in = implode(',', array_map( 'absint', $sticky_posts ));
// honor post type(s) if not set to any
$stickies_where = '';
if ( 'any' != $post_type && '' != $post_type ) {
if ( is_array( $post_type ) ) {
$post_types = join( "', '", $post_type );
} else {
$post_types = $post_type;
}
$stickies_where = "AND $wpdb->posts.post_type IN ('" . $post_types . "')";
}
$stickies = get_posts( array(
'post__in' => $sticky_posts,
'post_type' => $post_type,
'post_status' => 'publish',
'nopaging' => true
) );

$stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" );
foreach ( $stickies as $sticky_post ) {
// Ignore sticky posts the current user cannot read or are not published.
if ( 'publish' != $sticky_post->post_status )
continue;
array_splice($this->posts, $sticky_offset, 0, array( get_post( $sticky_post ) ) );
array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
$sticky_offset++;
}
}
Expand Down

0 comments on commit 7515511

Please sign in to comment.