1

Story below looks to me like it's about a commercial Event Management plugin whose authors to me just don't seem very good at WordPress. But bear with me and let's see if there's also an issue in WP. This is on 3.5.2.

Chain of events I'm looking into:

  • custom taxonomy query is made in browser

  • $wp_the_query gets all results (1 post total), WordPress sets $GLOBALS['post'] to this post

  • in "wp" action, commercial plugin builds new WP_Query (meta query, resulting in a correct EMPTY RESULT SET), then replaces global $wp_query with this empty result by bluntly doing $wp_query = $this->_wp_query;

  • but nobody touches $GLOBALS['post'], so all subsequent get_post() calls see $wp_query->post not being there, fall back on $GLOBALS['post'] and cause incorrect results (post_class() and friends, who think they have an <article> element to work with)

If I manually hook into "wp" action after commercial plugin has finished its' query and do $GLOBALS['post'] = null, template will correctly reflect reality.

  • we have even more fun when for example Yoast's SEO plugin does wp_reset_query() for its own magic in "wp_head" action, which will resurrect global $post variable from $wp_the_query after I've nulled it earlier in "wp"

So this is some sort of an issue with empty result set custom queries. I have not see any guidelines so far to care for resetting global $post variable like this. While the plugin is just badly built, should there be something for this addressed in core?

  • There is too much information missing/too much going on but I am suspicious of anything that replaces $wp_query, especially if it doesn't get put back. – s_ha_dum Jul 8 '13 at 23:32
  • I think I will just destroy the original query with "posts_where" filter from inside "pre_get_posts". That should restore sanity to the world. – lkraav Jul 9 '13 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.