Hi all,
I have built an VUE SPA with discourse API to use on Wordpress, and was wondering if there’s way to send a POST request to update the Topic view count to discourse when user open the Topic on Wordpress?
Hi all,
I have built an VUE SPA with discourse API to use on Wordpress, and was wondering if there’s way to send a POST request to update the Topic view count to discourse when user open the Topic on Wordpress?
Hey Alex,
I’m curious to learn a little more about this. Anything you can share?
Viewing posts pulled by the WP Discourse plugin doesn’t create new views in Discourse, however if you use the standard show
endpoint in the topics_controller
, and you pass the check highlighted below, the “view” will be tracked. Note that using an api key will mean there’s a current_user
.
One gotcha to note when you’re reading that code is that TopicView
is not actually the droid you’re looking for (it’s a model that handles the data serialized when a topic is shown). The actual “topic view” model is TopicViewItem
.
Hi @angus,
Thank you for your insight. I will look into the code base for topic views.
Regarding the SPA app:
Originally we had a forum plugin on Wordpress, they creates their own post type for questions and answers as well as category and tags. Upon setting up the SSO with WP Discourse plugin, I enabled Webhooks on discourse to sync topics to Wordpress with that post type, and using the embedding for answers.
At this point, the forum frontend is boring since each question item relying on its WP data only able to show title and author and I’d like to show the posters, views, likes and replies status as well. It didn’t make sense to me to modify that plugin.
With a SPA, pulling and display data would been much faster and flexible. It shows paginated latest topics, and a sidebar with Top topics, included with filter/search capability.
Originally, in the topic details view, I wanted to handle displaying the answers/replies as well. For some reason, the embedded replies was showing posters’ username instead of full name.
I also came across problems with the emoji and other assets are relative to the discourse site, so I fallback to stick with embeds.
Another problem was SEO, I was able to handle it with wp_head
hook in WordPress.