• Hey guys,
    I’ve got a very weird issue on my blog with the comments.

    Just Bullsin

    Basically, the first post currently (titled 72 Win Bulls: The Best Ever) has 2 comments on it which you can see when you click into the post and scroll down. The third post currently (titled How Quickly They Forget) has no comments on it as you can see by clicking into it and scrolling down. However, if you try to add a comment to the first post, it posts correctly in that post although the comment number on the home page increases for the third post and the first still shows 0 comments even though the comment shows up in the first post.

    I checked the database and the comments, for whatever reason, are saving to the post ID that is associated with the third post, NOT the first, which is incorrect. What’s going on here?

    Thanks for any help anyone can offer because I’m just dumbfounded right now.

    Matt

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter mprzybylski

    (@mprzybylski)

    by the way, this is what I’m using in the loop to display comment numbers:

    <a href="<?php comments_link(); ?>"><?php comments_number('No Comments','1 Comment','% Comments'); ?></a>

    Thread Starter mprzybylski

    (@mprzybylski)

    Anyone? Really need to get this figured out 🙁

    Have you tried:

    – deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    – switching to the Twenty Ten theme to rule out any theme-specific problems.

    resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.

    the code of the ‘related posts’ section is very likely messing with the query; i.e. it is destroying the connection between the comments and the post, possibly by changing the post object.

    find that code and fix it.

    or paste it here (use a http://pastebin.com/ if that code is longer than 10 lines) for someone to have a look at it.

    Thread Starter mprzybylski

    (@mprzybylski)

    @esmi: I have not tried that yet but will as soon as I get home.

    @alchymyth: Here is the code for the related posts:

    <?php
    					$tags = wp_get_post_tags($post->ID);
    
    					if ($tags) {
    						$tag_ids = array();
    						foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
    
    						$args=array(
    							'tag__in' => $tag_ids,
    							'post__not_in' => array($post->ID),
    							'showposts'=>5, // Number of related posts that will be shown.
    							'caller_get_posts'=>1
    						);
    						$my_query = new wp_query($args);
    						if( $my_query->have_posts() ) {
    							echo '<h4>Related Posts</h4><ul class="related_posts">';
    							while ($my_query->have_posts()) {
    								$my_query->the_post();
    							?>
    								<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> by <?php the_author_posts_link(); ?></li>
    							<?php
    							}
    							echo '</ul>';
    						}
    					}
    				?>

    try and add wp_reset_postdata(); after echo '</ul>';

    example code from the codex: http://codex.wordpress.org/The_Loop#Nested_Loops

    Thread Starter mprzybylski

    (@mprzybylski)

    @alchymyth: that worked! I just had to move the comments to the correct post ID in the DB but after that posting a comment now goes to the correct post. thanks so much, really appreciate your help.

    you might want to pass the info on to the source where you got the theme from; this might help to avoid confusion for future users of the theme.

    Thread Starter mprzybylski

    (@mprzybylski)

    I totally would but I don’t remember where I got the code from. It wasn’t part of the theme, it was something I had found online. I customized the theme a TON when putting this together.

    thanks for reporting back;
    that is fine.
    code snippets on the web don’t always take full precautions to keep the original query undisturbed.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Comments number incorrect in loop’ is closed to new replies.