# Hoe de Topic weergavetelling te synchroniseren met de discourse?

**URL:** https://meta.discourse.org/t/how-to-sync-the-topic-view-count-back-to-the-discourse/230129
**Category:** WordPress
**Tags:** rest-api
**Created:** [15 juni 2022 om 23:24 UTC](https://meta.discourse.org/t/how-to-sync-the-topic-view-count-back-to-the-discourse/230129 "2022-06-15T23:24:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![j3ang](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j3ang/32/251087_2.png) [@j3ang](https://meta.discourse.org/u/j3ang)
#### Post date: [15 juni 2022 om 23:24 UTC](https://meta.discourse.org/t/how-to-sync-the-topic-view-count-back-to-the-discourse/230129/1 "2022-06-15T23:24:27Z")

</div>

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?

---

<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: [16 juni 2022 om 06:50 UTC](https://meta.discourse.org/t/how-to-sync-the-topic-view-count-back-to-the-discourse/230129/2 "2022-06-16T06:50:45Z")

</div>

Hey Alex,

> [@j3ang](#):
>
> I have built an VUE SPA with discourse API to use on Wordpress

I’m curious to learn a little more about this. Anything you can share?

> [@j3ang](#):
>
> 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?

Viewing posts pulled by the [WP Discourse](https://github.com/discourse/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`.

> <https://github.com/discourse/discourse/blob/c625dc0adcff0a6c2a2c64b63f2f76185e1a555c/app/controllers/topics_controller.rb#L1172>

### Note

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`.

---

<div class="post-metadata">

### Author: ![j3ang](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j3ang/32/251087_2.png) [@j3ang](https://meta.discourse.org/u/j3ang)
#### Post date: [16 juni 2022 om 16:49 UTC](https://meta.discourse.org/t/how-to-sync-the-topic-view-count-back-to-the-discourse/230129/3 "2022-06-16T16:49:56Z")

</div>

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](https://github.com/discourse/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**](https://meta.discourse.org/t/how-to-display-full-name-in-comments-embeds/228020).

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.
