[Resolved] Comments showing on a page they shouldn't…

Home Forums Support Comments showing on a page they shouldn't…

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #903865
    Leo

    JUST switched to generatepress. Quite happy so far. πŸ™‚

    This is a page that as you can see lists recent posts: https://askleo.com/all-entries-by-date/
    The problem is that it includes comments for the last post in the list. That list is generated by a custom shortcode that essentially does a “new WP_Query” and walks the results. My guess is that it’s leaving something open that shouldn’t be? Anyway, if you have any clues that might lead me to fixing the behavior, that would be awesome.

    Thanks,

    Leo

    #903868
    Leo
    Staff
    Customer Support

    Hi there,

    Can you share the code you are using?

    Make sure to highlight it and click code button in the editor πŸ™‚

    #903880
    Leo

    You mean my shortcode? Sure, here’s a snippet of relavence:

      $archive_query = new WP_Query($rgQueryParams);
      $szResult = "";
      $szResult .= "<ul style='list-style: none; margin-left: 0; padding-left: 6em; text-indent: -6em;'>\n";
      while ($archive_query->have_posts() && $szCount)
        {
        $archive_query->the_post();
        $szCount--;
        $szResult .= "<li>" . get_the_date("Y-m-d") . " <a href=\"" .  get_permalink() . "\" title=\"" . get_the_title() . "\">" . get_the_title() . "</a></li>\n";
        }
      $szResult .= "</ul>\n";
    

    This is in the shortcode function, so there are no globals involved. The only thing I can think of is that perhaps I’m leaving some global state by not walking the full set of restults returned by WP_Query. (There’s a count to limit the length of what gets output.)

    #903940
    Leo

    Heh. Nevermind, fixed it on my own. Missing a call to wp_reset_postdata();

    Thanks,

    Leo

    #903953
    Leo
    Staff
    Customer Support

    Glad you figured out πŸ™‚

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.