Site logo

[Resolved] Pages and posts display unrealistic number for number of comments

Home Forums Support [Resolved] Pages and posts display unrealistic number for number of comments

Home Forums Support Pages and posts display unrealistic number for number of comments

  • This topic has 11 replies, 2 voices, and was last updated 5 years ago by Leo.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1700599
    Dusan

    So my posts and pages have comments enabled and I have a few comments published.

    I haven’t noticed this before so I don’t know when did this start happening but I am sure that it wasn’t immediately upon installing the generate press as that was a while ago.

    The real number of comments is way less than what it says above the comments.

    I am sending you a link to a page that has 7 comments but it says that it has 64. How is this even possible?
    What can I do to fix this?

    #1700662
    Leo
    Staff
    Customer Support

    Hi there,

    That’s odd. Haven’t seen this issue before.

    Can you disable all plugins to eliminate any conflicts first?

    If that doesn’t help, can you confirm that the issue still exists with a Twenty series WP theme?

    The comment system is all handled by WordPress itself so it’s unlikely a theme issue.

    #1700676
    Dusan

    Hi Leo,

    I deactivated my W3 cache plugin and minifying.

    I can’t deactivate all of my plugins without ruining the visitor’s experience..

    Before I noticed this I did delete a few older plugins that were deactivated anyway for a long time and were just idly sitting in my plugins tab. But I doubt that that had anything to do with this.

    Can you check my site without the W3 caching and minifying?

    The problem does persist if I preview the 2021 theme. I didn’t activate it but just clicked on preview and the big number of comments is there. I have no clue what is happening 🙁

    #1700678
    Leo
    Staff
    Customer Support

    Since the issue exists in a 2021 theme, that’s telling us that it’s not a GP issue so not something we can fix from our end.

    I’d recommend starting a staging site, activate 2021 theme, disable all plugins and see if the issue still exists.

    If so then it would be a good idea to start a support topic with WordPress’ support team and see if they have seen similar issue before.

    #1700681
    Dusan

    Now I checked in my wordpress dashboard comments area per post it says that weird big numeber in that little comment box. But when I click to the comment box to actually see these comments it only shows the actual comments which are much less..

    Now I see that this is not theme-related.. But do you have any tips for me? What could I look into?

    Thank you

    #1700685
    Leo
    Staff
    Customer Support

    My tips are actually in the reply above:
    https://generatepress.com/forums/topic/pages-and-posts-display-unrealistic-number-for-number-of-comments/#post-1700678

    Looks like we replied at the same time 🙂

    #1700763
    Dusan

    Hi Leo,

    I did what you suggested but none of it helped. However it lead me to this.

    When I preview my previous theme everything works good with the comments so I did a little digging in my staging envrioment. It turns out that my previous theme uses a bit different php code than the generate press and 2021 too? That is what seems to me but I am no expert.

    Can you take a look at these two codes please and let me know if I can edit a generate press php code somehow so that it works on my generatepress theme too?

    Here is the php code of comments of my previous theme from MythemeShop.

    <?php
     
    // Do not delete these lines
    if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
    die ('Please do not load this page directly. Thanks!');
     
    if ( post_password_required() ) { ?>
    <p class="nocomments"><?php _e('This post is password protected. Enter the password to view comments.','mythemeshop'); ?></p>
    <?php
    return;
    }
    ?>
    <!-- You can start editing here. -->
    <?php if ( have_comments() ) : ?>
    <span style="color: #a2a2a2;"><?php comments_number(__('No Responses','mythemeshop'), __('One Response','mythemeshop'),  __('Comments <span>(%)</span>','mythemeshop') );?></span>
    	<div id="comments">
    			<ol class="commentlist">
    				<div class="navigation">
    					<div class="alignleft"><?php previous_comments_link() ?></div>
    					<div class="alignright"><?php next_comments_link() ?></div>
    				</div>
    				<?php wp_list_comments('type=comment&callback=mts_comments'); ?>
    				<div class="navigation">
    					<div class="alignleft"><?php previous_comments_link() ?></div>
    					<div class="alignright"><?php next_comments_link() ?></div>
    				</div>
    			</ol>
    		</div>

    And here is the code from generatepress comments php file

    <div id="comments">
    
    	<?php
    	/**
    	 * generate_inside_comments hook.
    	 *
    	 * @since 1.3.47
    	 */
    	do_action( 'generate_inside_comments' );
    
    	if ( have_comments() ) :
    		$comments_number = get_comments_number();
    		$comments_title = apply_filters(
    			'generate_comment_form_title',
    			sprintf(
    				esc_html(
    					/* translators: 1: number of comments, 2: post title */
    					_nx(
    						'%1$s thought on &ldquo;%2$s&rdquo;',
    						'%1$s thoughts on &ldquo;%2$s&rdquo;',
    						$comments_number,
    						'comments title',
    						'generatepress'
    					)
    				),
    				number_format_i18n( $comments_number ),
    				get_the_title()
    			)
    		);

    As far as I can tell there is some kind of a difference in the part “generate comments number”. I am not sure that they work the same. I am no coding expert but this is just an observation I made because the comment number is properly displayed when using the MythemeShop theme which is incredibly slow and I dont like it. If there is a difference in code can you please tell me what to use in generatepress code?

    Thank you again

    #1700970
    Leo
    Staff
    Customer Support

    Not sure if I fully understand.

    By default, GP (and 2021 WP default theme) should show the correct comment number without any modification to the code.

    Are you adding any custom functions that might be interfering?

    #1700981
    Dusan

    Hi Leo,

    Thank you for your reply.

    I am not using any special code that could interfere.

    But since I did use the mythemeshop’s theme before.. could it be possible that their theme made changes to my wordpress files or something like that?
    The culprit appears to be connected with their theme. Because their theme displays the proper number of comments.. I wish if possible to modify my generatepress theme to display the comments just like their does if that is possible so that it works.

    I am not sure what to do.. This is one of those unexplainable things that just happen 🙁
    Additionally I think that this may have happened after the 5.7 update. I would have noticed this before. And the only thing that recently changed was that update..

    #1701035
    Leo
    Staff
    Customer Support

    would it be possible that their theme made changes to my WordPress files or something like that?

    I don’t think so but it’s certainly possible. You could try reinstalling WordPress.

    It’s not possible to modify GP’s code to display the comment number correctly as the code already does that.

    You will need to figure what could be interfering with it and eliminate the issue that way.

    #1701685
    Dusan

    I fixed it. Here is how if anyone gets in a similar problem.

    In the database for wp_posts in the column for comments somehow these wrong numbers got in.

    All it took was to call a php function to update the comments row in the wp_posts from the actual comments database from wp_comments.

    Since I didnt manage to figure this out on my own I used a plugin that updated the database. This one https://wordpress.org/plugins/update-comment-count/ additionally I also had to use a database cleaner plugin to delete all the spam comments. I used this one https://wordpress.org/plugins/advanced-database-cleaner/

    #1702373
    Leo
    Staff
    Customer Support

    Thanks for sharing your solution!

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.