[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
Wed Dec 18 20:50:20 UTC 2019
#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):
This problem is very frustrating, and affects a lot of plugins. For
example, Yoast SEO processes shortcodes on restoring a revision, which can
result in being redirected to the wrong page after the revision is
restored.
And they don't want to fix it, given it's a WordPress core issue:
https://github.com/Yoast/wordpress-seo/issues/12017
The approach above was suggesting setting up an entire `WP_Query` loop on
the admin page, which I can imagine could be tricky.
Rather than having to add hacky code throughout all plugins and a large
number of other locations to backup and save the $post variable every time
it might change, how about simply doing this once? When `$post` is first
created in the admin, save it; then adjust the `wp_reset_postdata`
function to restore it if you're in the admin.
That way plugins/shortcodes can continue to use `wp_reset_postdata` in the
normal way.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/18408#comment:30>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list