If you publish the posts through WP Discourse and setup the ‘Sync Comment Data’ webhook, it will store the Discourse comments count as post meta data with the key discourse_comments_count
. If you’re not using the WP Discourse comments template for displaying the comments, you’ll need to write a function that hooks into the WordPress get_comments_number
filter and returns the discourse_comments_count
value.
You can do this without setting up a webhook. It’s a lot more efficient with it though.
Edit: the Sync Comment Data webhook only updates the comment numbers and tells the WP Discourse plugin to update the comment content the next time the page is displayed, so using it to update the comment numbers when the WP Discourse comments template isn’t being used should be quite efficient. You can see the logic of it here: https://github.com/discourse/wp-discourse/blob/master/lib/discourse-webhook-refresh.php#L149.