Make WordPress Core

Changes between Version 1 and Version 2 of Ticket #18408, comment 33


Ignore:
Timestamp:
02/26/2021 09:32:07 PM (4 years ago)
Author:
smerriman
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #18408, comment 33

    v1 v2  
    1 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.
     1Just 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, dynamic blocks, or admin code to run their own custom queries.
    22
    3 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.
     3I'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, and may run shortcodes etc), the `$post` variable is also broken as it is reset to the incorrect value.
    44
    55Is the true situation here that there is no admin bug at all - and indeed it is *incorrect* for any shortcode, dynamic block, or custom code in the admin, 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?)