• so im trying to make wordpress loop with nubmer of comments show per post. I just want posts from one category. Loop is working, but number of comments are not correct. On every single post it just say that there is no comments (even when i have 10 or more commentes there)

    <?php
                    $query = new WP_Query('category_name=blog&post_type=post');
                    if ($query->have_posts()) :
                        ?>
                    <?php
                        // Start the loop.
                    while ($query->have_posts()) : $query->the_post();
    ?>
                    <div class="col-12 col-md-6 blog_single_homepage">
                            <div class="col-12">
                                <div class="row align-items-end">
                                    <div class="col-5 col-md-3 autor_section">
    
                                       <?php echo get_avatar( get_the_author_meta('user_email'), '150', $default, $alt, array( 'class' => array( 'rounded-circle' ) ) ); ?>
                                    </div>
                                    <div class="col-7 col-md-9 autor_info">
                                        <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>" class="autor_name"><?php the_author(); ?></a>
                                        <span class="align-middle"><?php the_time('d/m/Y'); ?></span>
                                        <div class="cat">
                                            <p><?php the_category(', '); ?></p>
                                        </div>
                                        <hr>
                                    </div>
                                </div>
                            </div>
                            <div class="col-12 blog_content_short">
                                <a href="<?php the_permalink(); ?>">
                                    <h3><?php the_title() ?></h3>
                                    <p><?php echo wp_trim_words(get_the_content(), 50); ?></p>
                                    <div class="read_more_over">
                                        <div class="title_inner">
                                            <?php the_title() ?>
                                        </div>
                                        <div class="inner_show">
                                            Read more
                                        </div>
                                    </div>
                                </a>
                                <div class="comments">
                                    <?php 
    printf( _nx( 'One Comment', '%1$s Comments', get_comments_number(), 'comments title', 'textdomain' ), number_format_i18n( get_comments_number() ) );
    
    ?>
                                </div>
                            </div>
                        </div>
                    <?php
                        // End the loop.
                    endwhile;
                    else :
                        echo 'No blog posts...';
    
                    endif;
                    ?>

    numbers of approved comments

Viewing 2 replies - 1 through 2 (of 2 total)
  • first get your post id then use this dude
    <?php wp_count_comments( post_id ); ?>

    your code works in a child theme of Twenty Seventeen.
    either you don’t have comments on those posts, or your theme or some plugin might be interfering.

    try to temporarily switch to the default theme Twenty Seventeen, and add your code there into the respective template, and temporarily try to deactivate all plugins, to see if that makes any difference.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress is not showing number of comments per post’ is closed to new replies.