[wp-trac] [WordPress Trac] #9978: Sticky Posts are not ordered correctly after selection

WordPress Trac noreply at wordpress.org
Wed Sep 25 19:24:44 UTC 2013


#9978: Sticky Posts are not ordered correctly after selection
-------------------------+-----------------------------
 Reporter:  beaulebens   |       Owner:  ryan
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  Query        |     Version:  2.8
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+-----------------------------

Comment (by jeremyfelt):

 {{{
 // Loop over posts and remove stickies.
 foreach ( $this->posts as $i => $post ) {
         if ( in_array( $post->ID, $sticky_posts ) ) {
                 // Remove sticky from current position
                 array_splice( $this->posts, $i, 1, true );
         }
 }
 }}}

 In `array_splice()` here, `$this->posts` is rekeyed each time. As the
 posts are looped through, it is possible that `$i` stops matching and
 results in the removal of an incorrect post. We can add a 4th parameter to
 `array_splice()` to maintain the value, and then reindex it on our own
 after. Not sure if that's the best approach or not.

 Also, `orderby` is not filled in `fill_query_vars()`, so an undefined
 index notice may be thrown when `$q['orderby']` is referenced for the
 sticky post query if the query hasn't been filtered.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/9978#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list