Archived topic
Comments showing on a page they shouldn't...
4 replies · Started by Leo on May 18, 2019
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
Hi there,
Can you share the code you are using?
Make sure to highlight it and click code button in the editor :)
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.)
Heh. Nevermind, fixed it on my own. Missing a call to wp_reset_postdata();
Thanks,
Leo
Glad you figured out :)