Ignore sticky posts which the current user cannot read, Ignore sticky posts which have been explicitly excluded with 'post__not_in'. Fixes #11197

git-svn-id: http://svn.automattic.com/wordpress/trunk@14217 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-04-24 06:04:05 +00:00
parent 5bde56c788
commit 79dea16d7f
1 changed files with 7 additions and 2 deletions

View File

@ -2465,6 +2465,10 @@ class WP_Query {
}
}
// If any posts have been excluded specifically, Ignore those that are sticky.
if ( !empty($sticky_posts) && !empty($q['post__not_in']) )
$sticky_posts = array_diff($sticky_posts, $q['post__not_in']);
// Fetch sticky posts that weren't in the query results
if ( !empty($sticky_posts) ) {
$stickies__in = implode(',', array_map( 'absint', $sticky_posts ));
@ -2478,10 +2482,11 @@ class WP_Query {
}
$stickies_where = "AND $wpdb->posts.post_type IN ('" . $post_types . "')";
}
$stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" );
/** @todo Make sure post is published or viewable by the current user */
foreach ( $stickies as $sticky_post ) {
if ( 'publish' != $sticky_post->post_status )
// Ignore sticky posts the current user cannot read or are not published.
if ( !current_user_can('read_post', $sticky_post->ID) || 'publish' != $sticky_post->post_status )
continue;
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
$sticky_offset++;