| 2474 | | $sticky_posts = get_option('sticky_posts'); |
| 2475 | | if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['caller_get_posts'] ) { |
| 2476 | | $num_posts = count($this->posts); |
| 2477 | | $sticky_offset = 0; |
| 2478 | | // Loop over posts and relocate stickies to the front. |
| 2479 | | for ( $i = 0; $i < $num_posts; $i++ ) { |
| 2480 | | if ( in_array($this->posts[$i]->ID, $sticky_posts) ) { |
| 2481 | | $sticky_post = $this->posts[$i]; |
| 2482 | | // Remove sticky from current position |
| 2483 | | array_splice($this->posts, $i, 1); |
| 2484 | | // Move to front, after other stickies |
| 2485 | | array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); |
| 2486 | | // Increment the sticky offset. The next sticky will be placed at this offset. |
| 2487 | | $sticky_offset++; |
| 2488 | | // Remove post from sticky posts array |
| 2489 | | $offset = array_search($sticky_post->ID, $sticky_posts); |
| 2490 | | unset( $sticky_posts[$offset] ); |
| | 2474 | if ( $this->is_home && $page <= 1 && !$q['caller_get_posts'] ) { |
| | 2475 | $sticky_posts = get_option('sticky_posts'); |
| | 2476 | |
| | 2477 | if ( is_array($sticky_posts) && !empty($sticky_posts) ) { |
| | 2478 | $num_posts = count($this->posts); |
| | 2479 | $sticky_offset = 0; |
| | 2480 | // Loop over posts and relocate stickies to the front. |
| | 2481 | for ( $i = 0; $i < $num_posts; $i++ ) { |
| | 2482 | if ( in_array($this->posts[$i]->ID, $sticky_posts) ) { |
| | 2483 | $sticky_post = $this->posts[$i]; |
| | 2484 | // Remove sticky from current position |
| | 2485 | array_splice($this->posts, $i, 1); |
| | 2486 | // Move to front, after other stickies |
| | 2487 | array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); |
| | 2488 | // Increment the sticky offset. The next sticky will be placed at this offset. |
| | 2489 | $sticky_offset++; |
| | 2490 | // Remove post from sticky posts array |
| | 2491 | $offset = array_search($sticky_post->ID, $sticky_posts); |
| | 2492 | unset( $sticky_posts[$offset] ); |
| | 2493 | } |
| 2498 | | // Fetch sticky posts that weren't in the query results |
| 2499 | | if ( !empty($sticky_posts) ) { |
| 2500 | | $stickies__in = implode(',', array_map( 'absint', $sticky_posts )); |
| 2501 | | // honor post type(s) if not set to any |
| 2502 | | $stickies_where = ''; |
| 2503 | | if ( 'any' != $post_type && '' != $post_type ) { |
| 2504 | | if ( is_array( $post_type ) ) { |
| 2505 | | $post_types = join( "', '", $post_type ); |
| 2506 | | } else { |
| 2507 | | $post_types = $post_type; |
| | 2500 | // Fetch sticky posts that weren't in the query results |
| | 2501 | if ( !empty($sticky_posts) ) { |
| | 2502 | $stickies__in = implode(',', array_map( 'absint', $sticky_posts )); |
| | 2503 | // honor post type(s) if not set to any |
| | 2504 | $stickies_where = ''; |
| | 2505 | if ( 'any' != $post_type && '' != $post_type ) { |
| | 2506 | if ( is_array( $post_type ) ) { |
| | 2507 | $post_types = join( "', '", $post_type ); |
| | 2508 | } else { |
| | 2509 | $post_types = $post_type; |
| | 2510 | } |
| | 2511 | $stickies_where = "AND $wpdb->posts.post_type IN ('" . $post_types . "')"; |
| 2512 | | $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" ); |
| 2513 | | foreach ( $stickies as $sticky_post ) { |
| 2514 | | // Ignore sticky posts the current user cannot read or are not published. |
| 2515 | | if ( 'publish' != $sticky_post->post_status ) |
| 2516 | | continue; |
| 2517 | | array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); |
| 2518 | | $sticky_offset++; |
| | 2514 | $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" ); |
| | 2515 | foreach ( $stickies as $sticky_post ) { |
| | 2516 | // Ignore sticky posts the current user cannot read or are not published. |
| | 2517 | if ( 'publish' != $sticky_post->post_status ) |
| | 2518 | continue; |
| | 2519 | array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); |
| | 2520 | $sticky_offset++; |
| | 2521 | } |