Display Posts Shortcode
[resolved] wp_reset_query() line in plugin was flaking my site out (3 posts)

  1. Jason Coleman
    Posted 4 years ago #

    Just an FYI, the call to wp_reset_query() on line 89 of version 1.5 of the script was making my site flake out.

    It must have reset the main WP query on the homepage so that that loop kept loading the homepage post over and over again. So my homepage looked like

    [homepage up until display posts shortcode]
    [homepage up until display posts shortcode]
    [homepage up until display posts shortcode]
    ... one on top of another until the server timed out.

    I'm not sure that a wp_reset_query() is necessary there since you are creating your own query object and not calling "query_posts" directly. You might want to use wp_reset_postdata function instead: http://codex.wordpress.org/Function_Reference/wp_reset_postdata

    This is kind of subtle stuff and I don't know the exact answer here.


  2. Jason Coleman
    Posted 4 years ago #

    FYI, I upgraded to the latest Display Posts Shortcode plugin and had to remove this line again.

  3. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    Any time a custom query is made, wp_reset_query() is required so that the global variables $post and $wp_query are reset to the proper query. wp_reset_postdata only resets $post.

    For instance, if you had a post, and in that post used the shortcode to list 5 other posts, if we didn't reset the query then your comments section would be comments for the last post in that list - not the actual post you're on.

    It sounds like it's an issue with your theme. Can you post the contents of front-page.php or home.php to http://gist.github.com, then post a link here?

    I'm marking this is resolved since it's been 5 months since your last message, but if you're still having an issue I'm happy to help resolve it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Display Posts Shortcode
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.