[wp-trac] [WordPress Trac] #64390: get_adjacent_post() SQL changes can loop infinitely in Storefront/derivative theme code
WordPress Trac
noreply at wordpress.org
Tue Dec 9 23:04:33 UTC 2025
#64390: get_adjacent_post() SQL changes can loop infinitely in
Storefront/derivative theme code
-------------------------------+------------------------------------
Reporter: jmdodd | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 6.9
Severity: normal | Resolution:
Keywords: | Focuses: template, performance
-------------------------------+------------------------------------
Comment (by ramonopoly):
Thanks for the heads up, and for the detailed explanation.
Do folks have any recommendations for making the changes in
https://github.com/WordPress/wordpress-develop/pull/10394/files more
defensive/plugin friendly?
Wondering if we could separate the date comparison from the ID tiebreaker
and add filters for each. I really don't know.
{{{#!php
<?php
// Build the date comparison
$date_comparison = $wpdb->prepare( ... );
// Build the ID tiebreaker for posts with identical dates
$id_tiebreaker = $wpdb->prepare(... );
// Combine into WHERE clause
$where_prepared = "WHERE ($date_comparison OR $id_tiebreaker) AND
p.post_type = " .
$wpdb->prepare("%s", $post->post_type) . " $where";
/**
* Filters the date comparison in the SQL for an adjacent post query.
*
* @param string $date_comparison The date comparison clause.
* @param string $current_post_date Current post's date.
* @param bool $previous Whether querying for previous post.
* @param WP_Post $post WP_Post object.
*/
$date_comparison = apply_filters(
"get_{$adjacent}_post_date_comparison",
$date_comparison,
$current_post_date,
$previous,
$post
);
// Rebuild WHERE with filtered date comparison
$where_prepared = "WHERE ($date_comparison OR $id_tiebreaker) AND
p.post_type = " .
$wpdb->prepare("%s", $post->post_type) . " $where";
// Apply the existing WHERE filter (now safer for plugins to use)
$where = apply_filters( "get_{$adjacent}_post_where", $where_prepared, ...
)
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64390#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list