Support for themes which use get_comments_number


(Stephen) #1

We’ve been fighting with a WordPress bug for four months now, our theme wasn’t reporting comment counts and the developer hasn’t been too helpful. After a lot of investigation and a little guidance from @benword we noticed that the theme uses get_comments_number, instead of comments_number which wp-discourse hooks into.

I was able to fix the comment counts for posts in the loop and on single pages by adding the below to libs/discourse.php at line 257:

function get_comments_number( $count ) {
    global $post;
    if( self::use_discourse_comments( $post->ID ) ) {
      self::sync_comments( $post->ID );
      $count = get_post_meta( $post->ID, 'discourse_comments_count', true );
    return $count;

But we’re still able to show comment counts elsewhere, including composer blocks.

Our developer is blaming wp-discourse and our modification of a WordPress function, but I can’t see any other obvious solutions. Any ideas?