[wp-trac] [WordPress Trac] #18408: Can't wp_reset_postdata after custom WP_Query in an admin edit page
WordPress Trac
noreply at wordpress.org
Fri Feb 26 21:28:23 UTC 2021
#18408: Can't wp_reset_postdata after custom WP_Query in an admin edit page
-----------------------------------------------+---------------------------
Reporter: ericlewis | Owner: ericlewis
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Future
| Release
Component: Query | Version: 4.7.2
Severity: normal | Resolution:
Keywords: needs-testing ongoing needs-patch | Focuses:
-----------------------------------------------+---------------------------
Comment (by smerriman):
Just wanted to chime in with an extra thought here. I've long considered
this a core WordPress bug - that `wp_reset_postdata` is the correct way
for shortcodes (or dynamic blocks) to run their own custom queries.
I've recently discovered, however, that it is not just the WordPress admin
that is affected by the call. If completely ordinary theme code runs a
custom loop and calls, for example, `the_excerpt` (which is empty, and
thus processes the full content in order to generate an automatic one),
the `$post` variable is also broken as it is reset to the incorrect value.
Is the true situation here that there is no admin bug at all - and indeed
it is *incorrect* for any shortcode or dynamic block to use
`wp_reset_postdata` in the first place? (With the solution by eg Bill
Erickson - save the `$post` variable and restore it afterwards - the
correct coding method?)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/18408#comment:33>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list