[wp-trac] [WordPress Trac] #58553: Two query blocks on home template (FSE) breaks the second one

WordPress Trac noreply at wordpress.org
Fri Jun 16 06:47:30 UTC 2023


#58553: Two query blocks on home template (FSE) breaks the second one
--------------------------+-----------------------------
 Reporter:  acaballerog   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  6.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 On a site we have a home.html template where we display a custom query
 with sticky posts before the main query (inherited). We also filter the
 main query to do not display sticky posts again. Since we updated to 6.1.3
 the second query skips the first post (that is the most recent non-sticky
 post).

 After some debugging I realize that the `$wp_query->current_post` value is
 0 after the first loop instead of -1, causing it to skip the first item
 (index 0) on the `$wp_query->posts array`. Following the logic in wp-
 includes I cannot find any obvious change introduced on 6.1.3 to produce
 this error.

 I’ve reproduced the issue on a fresh new installation of wp (with 6.2
 version):

 * I have created several posts (duplications of Hello world)
 * I have crated a new category.
 * I have assigned three posts to the new category
 * I have modified the home template (on the site editor) to add a custom
 query before the main one, where I display the three posts from the new
 category

 [[Image(https://images2.imgbox.com/3d/5c/wfm9rpvl_o.png)]]
 Result with wp 6.1.2

 When I update to 6.1.3, the “last one” disapears:

 [[Image(https://images2.imgbox.com/43/b0/OMZDY2ba_o.png)]]

 I have found a quick fix that solves it:

 {{{#!php
 <?php
 add_action('loop_end', function($query){
         if($query->is_home){
             global $wp_query;
             //sets the $wp_query->current_post to -1
             $wp_query->current_post = -1;
         }
 });
 }}}

 But I assume this may potentially affect more users and should be fixd on
 the core.

 BTW: Using two custom queries doesn’t work for us because we want to keep
 the default pagination settings with the `/page/2` urls

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


More information about the wp-trac mailing list