I use WP-Rocket on our site, but page caching (same issue if only using Cloudflare APO) is preventing the comment count from updating. I verified this by disabling WP-Rocket (and/or APO), posted a reply on the corresponding forum post and the comment count updates, but erratically. As in, not instant or as you might expect.
So I found a tip on adding a web hook and that allowed the comment count to reliably update.
However, with page caching on (WP-Rocket or APO), and using that web hook, the comment counts are not updating when someone posts a new reply in the forum.
The gist, it seems, the web hook is not triggering the WP environment properly to trigger the refresh of the cached page. It seems we might have a glitch in the matrix.
Edit: Another bit. I have WP-Rocket setup so when I am logged into Wordpress, the pages are not cached for me. Only for visitors. I noticed, I see comment counts update when I am logged into Wordpress, but I do not see them when I am a visitor in private browser mode.
Hey @Brandon007, thanks for explaining your issue. As I understand it:
The WP Discourse Plugin is updating comment counts correctly.
The WP Rocket cache is not being cleared when the comment counts are updated.
I’ve changed the title of your post from “WP Discourse Plugin Not Updating Comment Count” to “WP Discourse comment webhook does not trigger a WP Rocket Cache refresh”.
The basic answer to your issue is that this is expected behavior. The WP Discourse plugin doesn’t have any specific integration with WP Rocket and won’t be adding one in the foreseeable future.
But I can still help you here by adding in an action that fires after the comment sync webhook callback has updated the topic metadata (where the comment count is stored). You could then write your own action callback to do whatever cache clearing you desired. Would that work for your situation?
I’ll probably be lost writing code haha, but if you can make it possible. That puts me and other users one step in the right direction. It sounds like, with your modification it will allow user end code to be added to clear caching for any caching plugin. That would be even better than focusing on one product. I tried several cache methods on a dev site and they all had the same result anyway.
So carry on my good sir, and thanks for the response.
Hey Angus. I’m not sure if this was something you were still looking into?
Something else I wanted to add. Within native Wordpress, and using any form of page caching. Once a comment is left, the page cache purges on its own. Isn’t there a way where WP Discourse can mimic that behavior?
I’m not questioning your or anybody’s skills and I don’t know anything, but there can’t be anything like ”or any cache” because AFAIK WP Rocket needs different tools to purge its caching than W3 Total Cache than WP Fastest Cache than any reverse proxy like Varnish or Nginx.
And if WP Rocket is creating static part of page, aka. cache, from comment section there is much bigger issues than purging.
That’s correct. The WP Discourse plugin will simply provide an action that will allow sites using different caching solutions to purge the cache at the appropriate time using whatever method is appropriate to the caching solution being used.
Angus, thanks for the follow-up. Any general idea on the release date?
Also, is it possible for WP-Discourse to mimic the behavior of native Wordpress comments? Simply meaning, page cache solutions have an option, so the page cache can be cleared when a user leaves a new comment on that page. This is ideal.
As you know, as of today, we are unable to use page caching of any kind, if we want the comment count to increment. That’s a big drawback for Wordpress users who are concerned with speed optimizations.