From 3f9f8dc3d6aa9df00b968a8e81831067a5e4269d Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 5 Nov 2009 15:52:01 +0000 Subject: [PATCH] Honor Post Type for Sticky Posts. Props chrisscott. fixes #11072 git-svn-id: https://develop.svn.wordpress.org/trunk@12143 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/query.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 4a39dde583..668fadec5d 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2348,7 +2348,17 @@ class WP_Query { // Fetch sticky posts that weren't in the query results if ( !empty($sticky_posts) ) { $stickies__in = implode(',', array_map( 'absint', $sticky_posts )); - $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in)" ); + // 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" ); /** @todo Make sure post is published or viewable by the current user */ foreach ( $stickies as $sticky_post ) { if ( 'publish' != $sticky_post->post_status )