+ // 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 ));
+ // 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 = $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($sticky_post));
+ $sticky_offset++;
+ }
+ }
+ }
+
+ if ( !$q['suppress_filters'] )
+ $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) );