How to Show Comment Count on Related Posts?

get_comments_number works in the loop. You’re using it outside. So do something like this

    $category = get_the_category(); $category = $category[0]; $category = $category->cat_ID;
    $posts = get_posts('numberposts=5&offset=0&orderby=post_date&order=DESC&category='.$category);
    foreach($posts as $post){
      setup_postdata($post);
          $total = get_comments_number();
          echo 'here we create the HTML and content for the post';
    }
    wp_reset_query();

tech