I’ve been tackling this problem for the last few hours and cannot find out why nor find any help anywhere online.
So pretty much, I’m making a custom theme from scratch. WordPress always starts off with a default “Hello world!” post and a default comment associated with that post.
The “Hello world!” post should not evaluate to false but for some reason it does.
As you can see, I’ve tried using the comments_templates function WordPress offers to allow running code from a file named “comments.php” but that just added a factor of error to my problem and doing that, the code in “comments.php” is never even accessed, so for now, I’m leaving it out.
Img: What is shown when the code below is executed
Img: Proof there is a comment that should be shown
(I’m a newbie, so no embedded picture, sorry.)
<?php if(have_posts()) : while(have_posts()) : the_post(); get_template_part('content', get_post_format()); // comments_template('/comments.php', true); if(have_comments()) : echo 'OMG COMMENTS WORK'; foreach (get_comments() as $comment) : echo $comment -> comment_content; echo $comment -> comment_author; echo apply_filters('comment_text', $comment -> comment_content); endforeach; else : echo 'There are no comments to display here (this statement may or may not be true...)'; endif; endwhile; endif; ?>
Read more here: WordPress – Why does have_comments() not work?