diff --git wp-includes/query.php wp-includes/query.php
index 04286aa..284bea3 100644
|
|
class WP_Query { |
2745 | 2745 | } |
2746 | 2746 | |
2747 | 2747 | // Put sticky posts at the top of the posts array |
2748 | | $sticky_posts = get_option('sticky_posts'); |
2749 | | if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts'] ) { |
2750 | | $num_posts = count($this->posts); |
2751 | | $sticky_offset = 0; |
2752 | | // Loop over posts and relocate stickies to the front. |
2753 | | for ( $i = 0; $i < $num_posts; $i++ ) { |
2754 | | if ( in_array($this->posts[$i]->ID, $sticky_posts) ) { |
2755 | | $sticky_post = $this->posts[$i]; |
| 2748 | $sticky_posts = get_option( 'sticky_posts' ); |
| 2749 | if ( $this->is_home && $page <= 1 |
| 2750 | && is_array( $sticky_posts ) && ! empty( $sticky_posts ) |
| 2751 | && ! $q['ignore_sticky_posts'] ) { |
| 2752 | |
| 2753 | // Loop over posts and remove stickies. |
| 2754 | foreach ( $this->posts as $i => $post ) { |
| 2755 | if ( in_array( $post->ID, $sticky_posts ) ) { |
2756 | 2756 | // Remove sticky from current position |
2757 | | array_splice($this->posts, $i, 1); |
2758 | | // Move to front, after other stickies |
2759 | | array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); |
2760 | | // Increment the sticky offset. The next sticky will be placed at this offset. |
2761 | | $sticky_offset++; |
2762 | | // Remove post from sticky posts array |
2763 | | $offset = array_search($sticky_post->ID, $sticky_posts); |
2764 | | unset( $sticky_posts[$offset] ); |
| 2757 | array_splice( $this->posts, $i, 1 ); |
2765 | 2758 | } |
2766 | 2759 | } |
2767 | 2760 | |
2768 | 2761 | // If any posts have been excluded specifically, Ignore those that are sticky. |
2769 | | if ( !empty($sticky_posts) && !empty($q['post__not_in']) ) |
2770 | | $sticky_posts = array_diff($sticky_posts, $q['post__not_in']); |
| 2762 | if ( ! empty( $q['post__not_in'] ) ) |
| 2763 | $sticky_posts = array_diff( $sticky_posts, $q['post__not_in'] ); |
2771 | 2764 | |
2772 | 2765 | // Fetch sticky posts that weren't in the query results |
2773 | | if ( !empty($sticky_posts) ) { |
| 2766 | if ( ! empty( $sticky_posts ) ) { |
2774 | 2767 | $stickies = get_posts( array( |
2775 | 2768 | 'post__in' => $sticky_posts, |
2776 | 2769 | 'post_type' => $post_type, |
2777 | 2770 | 'post_status' => 'publish', |
| 2771 | 'order' => $q['order'], |
| 2772 | 'orderby' => $q['orderby'], |
2778 | 2773 | 'nopaging' => true |
2779 | 2774 | ) ); |
2780 | 2775 | |
2781 | | foreach ( $stickies as $sticky_post ) { |
2782 | | array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); |
2783 | | $sticky_offset++; |
2784 | | } |
| 2776 | foreach ( $stickies as $i => $sticky_post ) |
| 2777 | array_splice( $this->posts, $i, 0, array( $sticky_post ) ); |
2785 | 2778 | } |
2786 | 2779 | } |
2787 | 2780 | |