# WordPress / Discourse API Strategy: Get Reply Count via API Efficiently

**URL:** https://meta.discourse.org/t/wordpress-discourse-api-strategy-get-reply-count-via-api-efficiently/71943
**Category:** WordPress
**Created:** [October 12, 2017, 4:52pm UTC](https://meta.discourse.org/t/wordpress-discourse-api-strategy-get-reply-count-via-api-efficiently/71943 "2017-10-12T16:52:46Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 12, 2017, 5:28pm UTC](https://meta.discourse.org/t/wordpress-discourse-api-strategy-get-reply-count-via-api-efficiently/71943/3 "2017-10-12T17:28:27Z")

</div>

If you publish the posts through [WP Discourse](https://github.com/discourse/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](https://github.com/discourse/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](https://github.com/discourse/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](https://github.com/discourse/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](https://github.com/discourse/wp-discourse/blob/master/lib/discourse-webhook-refresh.php#L149).

---

_[View the full topic](https://meta.discourse.org/t/wordpress-discourse-api-strategy-get-reply-count-via-api-efficiently/71943)._
