[wp-trac] [WordPress Trac] #58147: bugfix: rewind_posts when posts array index != 0

WordPress Trac noreply at wordpress.org
Mon Apr 17 16:52:09 UTC 2023


#58147: bugfix: rewind_posts when posts array index != 0
--------------------------+-----------------------------
 Reporter:  diogovf       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  6.2
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 When the posts array doesn't start with the index 0, it generates an error
 due to hard code `0`.

 Before:
 {{{#!php
 <?php
 public function rewind_posts() {
     $this->current_post = -1;
     if ( $this->post_count > 0 ) {
         $this->post = $this->posts[0];
     }
 }
 }}}

 After:
 {{{#!php
 <?php
 public function rewind_posts() {
     $this->current_post = -1;
     if ( $this->post_count > 0 ) {
         $this->post = $this->posts[array_key_first($this->posts)];
     }
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58147>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list