How to debug a post on WP having the incorrect comment number

I just noticed a post on our WP site that displayed as having no comments, but I knew that it did receive on in Discourse. I left another one on that topic, and it also failed to show up. However, there are other posts receiving comments no problem. I can’t see anything weird or special about that post.

Is there anything I can do to debug the issue?

Make sure that the comments on the post are meeting the criteria you have set on the plugin’s Commenting options tab. If it seems that the posts comments should be getting pulled to WordPress, you could debug the issue by enabling the ‘Custom Fields’ screen option for posts on your site:

When that has been done, you will see a list of post metadata at the bottom of the edit screen. Make sure that the discourse_permalink and discourse_topic_id fields match the associated Discourse topic. If these fields are not present, it is possible that the post has been unlinked from Discourse. You can re-link an unlinked post by selecting the ‘Link to Existing Topic’ radio input from the Discourse meta box.

2 Likes

Thanks,

It gets weirder. I just watched as a comment came in on a brand new post. The home page of our WP site immediately showed one comment on that post. So far, looking good. Then, clicking through to the post, the info at the top showed there being one comment.

I clicked the number of comments to scroll down to the appropriate spot on the page, but instead of saying “Join the discussion” it said “Start the discussion.” (We don’t actually display the comments, just a count of them and the link to our Discourse instance.) I figured a page refresh would fix it, but instead, when I refreshed the page, it was back to saying there were zero comments. And the home page now updated back to zero as well.

I looked at the discourse_topic_id and discourse_permalink and they are both correct. The other discourse fields don’t make much sense to me, though.

discourse_comments_count says ‘0’

This is what’s in discourse_comments_raw:

{"id":1399,"posts_count":2,"filtered_posts_count":0,"posts":[],"participants":[{"id":11,"username":"nathan","name":"Nathan ","avatar_template":"https://www.ourdiscourse.com/user_avatar/www.ourdiscourse.com/nathan/{size}/182_2.png"},{"id":103,"username":"Zak","name":"Zak","avatar_template":"https://www.ourdiscourse.com/user_avatar/www.ourdiscourse.com/zak/{size}/652_2.png"}]}

Also, I can’t figure out what discourse_post_id is supposed to be, but just looking at the 4 digit number it contains, I would have expected it to be the WP post id, but it isn’t. What is it supposed to be?

If your Discourse topic is public, can you PM me a link to it?

Do you have the WP Discourse Publish as Unlisted Topics option enabled? The difference between the posts_count and the filtered_posts_count in the discourse_comments_raw metadata suggests that there are two small action posts in the topic. There is an issue with the WP Discourse webhook refresh function when there is a discrepancy between the posts_count and the filtered_posts_count. This is something I will deal with, but I don’t think it’s related to the issue you have with a post that is not receiving comments.

For the issue with the post that is not receiving comments, do you mean that the link to its Discourse topic is not being displayed, or is the issue that the link is displaying “start the discussion” instead of “join the discussion”?

1 Like

This.

It makes sense if the comment count is zero. I wouldn’t worry about that. It’s just what stood out to me and made me refresh the page and notice the count drop down to zero again.

1 Like

Oh, and to answer your question…

No.

1 Like

What is the proper value of the “wpdc_sync_post_comments” field?

I’m still struggling with this problem.

I just went to a topic that had one post. Comment count in the WP front-end should be “1”, but it showed 0. The wpdc_sync_post_comments was “0.” I’m assuming that’s a T/F flag, and that it should be set to 1, so I changed it and saved the post. Refreshing the WP front end showed no change, so I left a new post on the Discourse topic and immediately refreshed the WP page. Comment count had correctly jumped to “2.” Immediately refreshed the page again and it had dropped down to “0” again! In the edit screen, I found that wpdc_sync_post_comments was set back to 0 and

discourse_comments_count == 0
discourse_comments_raw ===
{"id":1451,"posts_count":3,"filtered_posts_count":1,"posts":[],"participants":[ (snip)

Another post has the following:
discourse_comments_count == 3
discourse_comments_raw ===
{"id":1447,"posts_count":17,"filtered_posts_count":4,"posts":[],"participants": (snip)

2 Likes

Thanks for the details!

When the field is set to 1, comments will be synced the next time the page is loaded. When the comments are synced the value of wpdc_sync_post_comments will be set back to 0.

From looking at the metadata you posted, it seems that the plugin is subtracting 1 from the comments number when it shouldn’t be. I’ve been travelling for the past couple of days. I’ll look at this closely when I get back to work tomorrow.

1 Like