#37312 closed defect (bug) (fixed)
Invalid call to wp_reset_postdata inside Recent Posts widget
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Widgets | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
If the global post object is from a query other than the main query, the recent posts widget will restore the wrong post object by calling wp_reset_postdata
.
$my_query = new WP_Query( $args );
$my_query->the_post();
// $GLOBALS['post'] is first post of $my_query
the_widget( 'WP_Widget_Recent_Posts' );
// $GLOBALS['post'] is restored to the main query's last accessed post
Attachments (2)
Change History (11)
#1
@
7 years ago
- Keywords has-patch added
Changing the loop to a foreach
negates the need to call the_post()
or wp_reset_postdata
.
#6
@
7 years ago
This change has caused an issue for the plugin Jquery Archives List Widget:
I have notified the author of that plugin but I also want to make sure that this change doesn't have bugs.
Reasonably sure that this change causes change in the behaviour of that plugin.
Can someone confirm that this ticket's changes hasn't caused unexpected behaviour?
#8
@
7 years ago
Earier, the code for "Recent Posts" had wp_reset_postdata().
Now not. I understand this fix removes wp_reset_postdata() from the code but shouldn't it be the case that it should run after the html for Recent Posts has been created?
It seems that if I want to do something, in Widgets, I have to first use wp_reset_postdata(). Is that logical?
Changing to foreach