• Resolved Jason Coleman

    (@strangerstudios)


    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: https://codex.www.ads-software.com/Function_Reference/wp_reset_postdata

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

    https://www.ads-software.com/extend/plugins/display-posts-shortcode/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Jason Coleman

    (@strangerstudios)

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

    Plugin Author Bill Erickson

    (@billerickson)

    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 https://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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Display Posts Shortcode] wp_reset_query() line in plugin was flaking my site out’ is closed to new replies.