# Should comments webhook update count after deleting posts/comments?

**URL:** https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621
**Category:** WordPress
**Created:** [November 17, 2024, 6:23pm UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621 "2024-11-17T18:23:21Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Firsh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firsh/32/454861_2.png) [@Firsh](https://meta.discourse.org/u/Firsh)
#### Post date: [November 17, 2024, 6:23pm UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/1 "2024-11-17T18:23:22Z")

</div>

I’m using DC SSO where users are managed by WP. The forum acts as a way to comment on posts, but these posts are only visible in the forum.

I have a custom “Comment” button in WP that turns into “x comments” when there are coments in the linked topic. (It uses normal WP `get_comments_number` that the DC plugin hooks into.)

It works well, but I’ve just tried deleting a post and the count remains the same. The UI in the WP plugin recommends:  
`Events: "Post is created", "Post is updated".`  
Based on that, it is perhaps not supported? To decrease or recalculate post/comment count.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [November 18, 2024, 8:35am UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/2 "2024-11-18T08:35:43Z")

</div>

I’m trying to understand how you’ve set this up. Please correct me if I’m wrong:

1. You use Publishing and [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) feature sets of the plugin.
2. You do (not) have “Enable Discourse Comments” enabled (?: this is unclear)
3. You have the “Sync Comment Data” webhook enabled.
4. You have added a custom button at the bottom of the Wordpress posts linked to Discourse that displays the count of Discourse posts on a topic. It uses the `get_comments_number` Wordpress filter.
5. You want the count to be updated when posts in the linked topic are deleted.

Is that right? What else have you set up (or not)?

---

<div class="post-metadata">

### Author: ![Firsh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firsh/32/454861_2.png) [@Firsh](https://meta.discourse.org/u/Firsh)
#### Post date: [November 18, 2024, 9:33am UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/3 "2024-11-18T09:33:49Z")

</div>

Yes to all except 2.

I do not have Enable Discourse Comments checked. I don’t use WP-native PHP display features at all, and this is part of a custom React UI, fed by an api va JS. The only thing I use related to comments is getting their count. Everything else is offloaded to Discourse behind a button.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [November 18, 2024, 9:49am UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/4 "2024-11-18T09:49:09Z")

</div>

Ok. I think adding `delete post` support to the [WP Discourse](https://github.com/discourse/wp-discourse) topic webhook is reasonable. I’ll do that in the next version (soon). I won’t be able to support your specific custom implementation, but I’ll add support for that event.

---

<div class="post-metadata">

### Author: ![Firsh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firsh/32/454861_2.png) [@Firsh](https://meta.discourse.org/u/Firsh)
#### Post date: [November 18, 2024, 1:21pm UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/5 "2024-11-18T13:21:01Z")

</div>

Thanks! As long as the comment count reflects the actual current count, changed for any reason, I can take it from there.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [December 4, 2024, 10:19am UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/6 "2024-12-04T10:19:30Z")

</div>

@Firsh Can you confirm whether this PR (now merged) fixed your issue?

[https://github.com/discourse/discourse/pull/29853](https://github.com/discourse/discourse/pull/29853)

---

<div class="post-metadata">

### Author: ![Firsh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firsh/32/454861_2.png) [@Firsh](https://meta.discourse.org/u/Firsh)
#### Post date: [December 4, 2024, 10:44am UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/7 "2024-12-04T10:44:10Z")

</div>

Plugin version 2.5.5  
DC version 3.4.0.beta3-dev ([876591fdab](https://github.com/discourse/discourse/commits/876591fdabbf085c5f7937a419f6aa08a2eeb893))

Settings for webhooks post events cover deleting and restoration (all checked).

- Posting a comment immediately increases the counter as expected.
- Upon deleting my only post in the topic, the counter in WP stays on 1.
- Upon restoring it stays on 1 as well.

So no, it doesn’t work, unless I’m supposed to perma-delete my post or wait 10 minutes or similar. I purged the caching plugin between refreshes as well.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [December 4, 2024, 10:47am UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/8 "2024-12-04T10:47:12Z")

</div>

> [@Firsh](#):
>
> DC version 3.4.0.beta3-dev ([876591fdab](https://github.com/discourse/discourse/commits/876591fdabbf085c5f7937a419f6aa08a2eeb893))

This version does not include the fix. Is it possible for you to update to the latest?

---

<div class="post-metadata">

### Author: ![Firsh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firsh/32/454861_2.png) [@Firsh](https://meta.discourse.org/u/Firsh)
#### Post date: [December 4, 2024, 11:08am UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/9 "2024-12-04T11:08:46Z")

</div>

For me, it says it’s the latest. I’ll wait until the newer update appears and perhaps start it during the night. I’d rather not update to an advance version if it involves manual update, as we only have a live site, no staging.

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [December 4, 2024, 12:27pm UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/10 "2024-12-04T12:27:53Z")

</div>

> [@Firsh](#):
>
> For me, it says it’s the latest

Discourse will only complain about being out of date on version changes, however lots of smaller changes get made in the middle and can be pulled in whenever you want by updating or rebuilding.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [January 3, 2025, 12:28pm UTC](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621/11 "2025-01-03T12:28:05Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
