Incorrect use of wp_reset_query();?
-
I’ve been struggling with what I thought was a bug in the Elementor Page Builder plugin and its interaction with The Events Calendar Shortcode plugin. It turns out that it’s probably the TECS plugin that’s at fault and not Elementor.
TECS uses
wp_reset_query();
on line 368 when I’m pretty sure it should bewp_reset_postdata();
instead.wp_reset_query();
is only required after usingquery_posts()
. TECS uses$wp_query
on line 140, which is the global instance of the WP_Query class, thuswp_reset_postdata();
should be used. From the WordPress Codex:Calling wp_reset_query is not necessary after using WP_Query or get_posts as these don’t modify the main query object. Instead use wp_reset_postdata.
Replacing
wp_reset_query();
withwp_reset_postdata();
fixes the ‘bug’ I had with Elementor and how it was using the current global post in its editing interface.
- The topic ‘Incorrect use of wp_reset_query();?’ is closed to new replies.