1

For some strange reason, comments aren't being displayed when a user is not logged in. I've done some extensive experimenting with comments.php without any success. Here's a reference to the example page:

http://gycweb.org/by-this-will-all-men-know/

If you are logged in, you would see 3 comments. If you are not logged in, nothing but the form. Also, to add to the mystery, when "editing" the post from within the admin and clicking "show comments", it tries and is not able to load the comments.

It appears that the "have_comments" conditional is failing for logged out users. I've also tried getting wp_list_comments to return the list with no success.

I've checked for plugin conflicts and nothing obvious yet. Have any of you run into this? Any obvious answers?

12
  • Can you post your comments.php template file code? Commented Jul 14, 2011 at 17:51
  • Here it is: pastebin.com/H5EeJrEp Commented Jul 14, 2011 at 19:44
  • And can you also post single.php and functions.php? Commented Jul 14, 2011 at 20:17
  • 1
    Um,oops... sorry for editing your question; thought I was editing an answer. Want me to pull that down into a comment? Commented Jul 14, 2011 at 23:04
  • 1
    My guess: You are using query_posts() somewhere, maybe in a widget/sidebar. This affects the main query.
    – fuxia
    Commented Jul 12, 2012 at 22:47

3 Answers 3

1

Probably your web-server user does not have permissions to create new files. I believe that WordPress caches comments on pages and posts for not logged users, so that only authenticated users get fresh comments list. When logged out user inputs a comment, the list gets updated with his comment too, which brings them the whole list (I tried that on my WP instance and yours, it works that way). Otherwise WP tries to get comments from a file, that it couldn't create beforehand, resulting in have_comments() returning false.

So, if you provide write permissions for www-data or whatever else is called your web-server user, you will forget for the problem.

The whole thing is still a theory, as I won't have access to my installation for about 10 days, but I strongly believe that this is the solution.

0

Toscho was right. I wound up having a query that was getting in the way. It took a bit of troubleshooting to figure out, but I nailed it.

If you run into similar issues, look carefully for any custom queries you may have on the template and make sure that you've wrapped them up properly.

-1

According to your original question, "If you are logged in, you would see 3 comments. If you are not logged in, nothing but the form.... It appears that the "have_comments" conditional is failing for logged out users."

Is your intention to show comments for all users, both logged in and out?

If you want comments to show for logged out users, then you need to remove this:

<?php if ( post_password_required() ) : ?>
            <p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'twentyten' ); ?></p>
        </div><!-- #comments -->

4
  • That's absolutely not true. "Logged-in users" != "post password required". The appropriate conditional would be is_user_logged_in(), not post_password_required(). Commented Jul 17, 2011 at 21:56
  • I see what you mean there. Another possibility is either the file is corrupted or the permission is wrong. Unless he has something else on other files controlling comment that he's not aware of.
    – Sean Lee
    Commented Jul 17, 2011 at 23:25
  • My best guess at this point is that it's one of the two Plugins he referenced. Commented Jul 18, 2011 at 0:05
  • you're probably right, and most likely the gyc_blog_comments function. perhaps function_exists did not recognize it, and stop to interpret the rest.
    – Sean Lee
    Commented Jul 19, 2011 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.