Make WordPress Core

Opened 13 months ago

#58553 new defect (bug)

Two query blocks on home template (FSE) breaks the second one

Reported by: acaballerog's profile acaballerog Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.2
Component: Query Keywords:
Focuses: Cc:


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
Result with wp 6.1.2

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

I have found a quick fix that solves it:

add_action('loop_end', function($query){
            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

Change History (0)

Note: See TracTickets for help on using tickets.