Forums

Comments number incorrect in loop (11 posts)

  1. mprzybylski
    Member
    Posted 11 months ago #

    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

  2. mprzybylski
    Member
    Posted 11 months ago #

    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>

  3. mprzybylski
    Member
    Posted 11 months ago #

    Anyone? Really need to get this figured out :(

  4. esmi
    Theme Diva & Forum Moderator
    Posted 11 months ago #

    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.

  5. alchymyth
    The Sweeper
    Posted 11 months ago #

    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.

  6. mprzybylski
    Member
    Posted 11 months ago #

    @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>';
    						}
    					}
    				?>
  7. alchymyth
    The Sweeper
    Posted 11 months ago #

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

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

  8. mprzybylski
    Member
    Posted 11 months ago #

    @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.

  9. alchymyth
    The Sweeper
    Posted 11 months ago #

    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.

  10. mprzybylski
    Member
    Posted 11 months ago #

    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.

  11. alchymyth
    The Sweeper
    Posted 11 months ago #

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

Reply

You must log in to post.

About this Topic