[wp-trac] [WordPress Trac] #56992: The Loop displays incorrect data for queries started with `fields => 'id=>parent'`.
WordPress Trac
noreply at wordpress.org
Tue Mar 11 00:07:12 UTC 2025
#56992: The Loop displays incorrect data for queries started with `fields =>
'id=>parent'`.
-------------------------------------------------+-------------------------
Reporter: peterwilsoncc | Owner:
| peterwilsoncc
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 6.8
Component: Query | Version: 3.1
Severity: normal | Resolution:
Keywords: 2nd-opinion has-patch has-unit- | Focuses:
tests dev-feedback | performance
-------------------------------------------------+-------------------------
Comment (by SirLouen):
Replying to [comment:31 peterwilsoncc]:
> If it just affected `global $post`, I might be fine with that but it
affects all the functions that are documented to the effect that "within
the loop, this function will return the value of the [thing] of the global
post" This includes:
>
> * `get_the_content()`
> * `get_the_excerpt()`
> * `get_the_title()`
> * `get_the_time()`
> * most other functions used in the loop and prefixed `get_` or `the_`
I'm doing myself a lot of questions with this topic. And one of the
biggest questions that comes to my mind is: Isn't a workaround, without
touching the core code, to achieve the same results?
Because the baseline is performant by default, but your "upgrade" hits
significantly the performance. If someone is currently using the
performant version (which is the mostly likely since the new version did
not exist for ages), he will have his site affected by this patch.
But if there is a workaround for your use-case that doesn't require the
core "upgrade" then your site will be impacted, but the rest of the sites
will remain untouched.
When I'm asking for a use-case, I'm asking for a plugin, either an
existing or a new one, that clearly requires this new upgrade and cannot
achieve the result because of the lacking functionality.
Here is my plugin, that is using the current version before this patch. It
doesn't require the "upgrade" and it works as expected
https://github.com/SirLouen/hierarchical-page-navigator
Just remember that now it's being impacted by a 40% extra overhead with
the current patch with no gains in functionality.
A workaround that comes to my mind, to populate template functions with
the original version could be done using
[https://developer.wordpress.org/reference/functions/setup_postdata/
setup_postdata]
{{{#!php
<?php
$query = new WP_Query([
'post_type' => 'page',
'fields' => 'id=>parent',
// Whatever else you want add to the query
]);
while ($query->have_posts()) {
$query->the_post();
global $post;
// And here you get full post object only when really needed
if (is_numeric($post) || $post instanceof stdClass) {
$post = get_post($post instanceof stdClass ? $post->ID : $post);
setup_postdata($post);
}
// Now the template functions should work correctly
the_title();
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56992#comment:32>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list