# Likes on a post

**URL:** https://meta.discourse.org/t/likes-on-a-post/96396
**Category:** Development
**Created:** [September 5, 2018, 9:03am UTC](https://meta.discourse.org/t/likes-on-a-post/96396 "2018-09-05T09:03:40Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Edwin\_Mhoy\_Silva](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/edwin_mhoy_silva/32/109980_2.png) [@Edwin\_Mhoy\_Silva](https://meta.discourse.org/u/Edwin_Mhoy_Silva)
#### Post date: [September 5, 2018, 9:03am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/1 "2018-09-05T09:03:40Z")

</div>

Do discourse keep count of who has liked which post ?  
I’m working on a method, which changes the color of the like icon, when a user have liked the post.  
I have made it so, that if a user likes a post, the “like-icon” changes from gray to red for all users.  
I only want it to change to red, if the user have liked that post.  
Is there some kind of variable or something I can use from the discourse platform?

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [September 5, 2018, 9:23am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/2 "2018-09-05T09:23:10Z")

</div>

I’m not sure I follow becuase that’s how it works now.

A topic / post with no likes looks like this:

![5](https://global.discourse-cdn.com/meta/original/3X/9/c/9c3d63aaa2558b2ea46d5ca9500b944d39baa5e1.png)

If it has likes but you didn’t like it, it shows up to you like this:

![6](https://global.discourse-cdn.com/meta/original/3X/7/9/791515d66d24192e6ded68159d626938fd64bc01.png)

If you liked it, it shows up like this to you:

![7](https://global.discourse-cdn.com/meta/original/3X/7/5/755baee12a7e69499c626b44750a3a5966e629ae.png)

Are you trying to change the color of the heart for posts you’ve liked?

---

<div class="post-metadata">

### Author: ![Edwin\_Mhoy\_Silva](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/edwin_mhoy_silva/32/109980_2.png) [@Edwin\_Mhoy\_Silva](https://meta.discourse.org/u/Edwin_Mhoy_Silva)
#### Post date: [September 5, 2018, 9:31am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/3 "2018-09-05T09:31:25Z")

</div>

Thanks for the reply.  
I have customized the discourse platform for a client

 ![59](https://global.discourse-cdn.com/meta/original/3X/0/8/085e3ef4583a87880049a0972ec65a2064e2d427.jpeg)  
What i’m trying to is to only change the color of the heart icon, if the current user have liked that post.  
The problem is, that the heart icons, changes color for all the users.  
I want to know if, discourse keep tap over who liked what?

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [September 5, 2018, 9:50am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/6 "2018-09-05T09:50:24Z")

</div>

In that case the answer to your question is yes.

`liked` is an attribute just like `like_count`. It should return true if you’ve liked the topic.

 ![8](https://global.discourse-cdn.com/meta/original/3X/d/e/de867f3146f0c67d4fb2fef6ac60016628282a5a.png)

---

<div class="post-metadata">

### Author: ![Edwin\_Mhoy\_Silva](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/edwin_mhoy_silva/32/109980_2.png) [@Edwin\_Mhoy\_Silva](https://meta.discourse.org/u/Edwin_Mhoy_Silva)
#### Post date: [September 5, 2018, 9:55am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/8 "2018-09-05T09:55:56Z")

</div>

I will give that a try  
This is an attribute from post/topic ?

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [September 5, 2018, 10:10am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/10 "2018-09-05T10:10:10Z")

</div>

It’s a topic attribute.

---

<div class="post-metadata">

### Author: ![Edwin\_Mhoy\_Silva](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/edwin_mhoy_silva/32/109980_2.png) [@Edwin\_Mhoy\_Silva](https://meta.discourse.org/u/Edwin_Mhoy_Silva)
#### Post date: [September 6, 2018, 6:34am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/14 "2018-09-06T06:34:13Z")

</div>

Okay I tested it in the postman

 ![12](https://global.discourse-cdn.com/meta/original/3X/4/e/4e2bed4e4e5bf7341dc29c2160dbfc412a1fe851.png)

As you can see the like\_count is 1.  
Why is my liked attribute null?

---

<div class="post-metadata">

### Author: ![Jesper\_Enemark](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesper_enemark/32/111051_2.png) [@Jesper\_Enemark](https://meta.discourse.org/u/Jesper_Enemark)
#### Post date: [September 20, 2018, 1:19pm UTC](https://meta.discourse.org/t/likes-on-a-post/96396/15 "2018-09-20T13:19:46Z")

</div>

In my system the property ‘liked’ that you are referring to is going from null to false upon liking. The id that is passed as ‘likesId’ _on the picture below_ is the id of the topic I am trying to like.  
Do you have any explanation for this behaviour, or possibly a solution, so that the property returns true as intended, upon posting a like? It seems to be hindered by something.

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/9/593ae3d6eb9a1dd442239645813eb7c14e63c008.png)  
Thank you

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [September 20, 2018, 2:29pm UTC](https://meta.discourse.org/t/likes-on-a-post/96396/16 "2018-09-20T14:29:38Z")

</div>

I may not be understanding, but are you trying to increment a post action (i.e. a like) by passing in a _topic_ id instead of a _post_ id? AFAIK, there is no such thing as a topic action.

---

<div class="post-metadata">

### Author: ![Jesper\_Enemark](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesper_enemark/32/111051_2.png) [@Jesper\_Enemark](https://meta.discourse.org/u/Jesper_Enemark)
#### Post date: [September 21, 2018, 6:21am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/17 "2018-09-21T06:21:01Z")

</div>

I realise there is no such thing as a topic action, but in my case I need something equivelant to topic\_action, otherwise, how does it make sense to like anything but a post?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [September 21, 2018, 8:37am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/18 "2018-09-21T08:37:42Z")

</div>

Well, Likes can be given only to posts. But Likes can be associated with other data. eg.

- number of Likes on posts made by a member (eg. the /user page)
- number of Likes on posts in a topic
- number of Likes on the first post of a topic

I don’t know what would be best considered as topic Likes. For example, which is “better”

- a topic with 100 posts where every other post got 1 Like (50 total for the topic)
- a topic with 2 posts where the second post got 40 Likes

They could be further broken down by eg. individual members contributing to the total, date/time ranges.

But again, which is “better”

- a topic with a total of 50 Likes all by one or few members
- a short topic with a total of 40 Likes by 40 different members.
- a year old topic with 50 Likes
- a week old topic with 40 Likes

---

<div class="post-metadata">

### Author: ![Jesper\_Enemark](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesper_enemark/32/111051_2.png) [@Jesper\_Enemark](https://meta.discourse.org/u/Jesper_Enemark)
#### Post date: [September 21, 2018, 8:56am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/19 "2018-09-21T08:56:39Z")

</div>

I have really been trying to understand the database structure and I admit to fail miserably at that. The only thing I can see is that on the live and dev site we have a difference in the response of a “not yet liked” idea. If you’d like to take a look at the responses I have some well documented pictures. It seems that liked property on the running site for “%liked” ideas is false, and on alpha site it is null by default.

Live:

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/7/778589c977a7598b46bf2a39436ca084542b78e1.jpeg)

Problem inducing Alpha site response:

 ![image](https://global.discourse-cdn.com/meta/original/3X/0/a/0a85b4741e73fe682eaf7f1c9d1d2ba2f82831da.jpeg)

These are both Topics and have not been liked.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [September 21, 2018, 9:31am UTC](https://meta.discourse.org/t/likes-on-a-post/96396/20 "2018-09-21T09:31:52Z")

</div>

That looks like JSON for the latest topic list page. The “liked” is whether or not you liked a post in the topic. (false if you read it but didn’t Like, null if you didn’t read it while logged in). The “like\_count” is the number of likes for all the posts in the topic combined.

Depending on what kind of information you want, there may not be what you need in that JSON alone. More intricate criteria may need to run a query against more than one table. Or maybe XHR calls to other pages to get their JSON.

I’m guessing your interest is to be able to show Like counts on topic list pages? Or are you interested in analyzing statistics? If it’s more a general interest in the database, checking out the schemas near the bottom of model files can help:  
[discourse/app/models at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/tree/master/app/models)

Or better, get familiar with the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin:

> [@Discourse Data Explorer](https://meta.discourse.org/t/data-explorer-plugin/32566):
>
> discourse2Summary Discourse [Data Explorer](https://meta.discourse.org/t/32566?silent=true) allows you to make SQL queries against your live database, allowing for up-to-the-minute stats reporting.open_bookInstall Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately.information_source If you’re looking for examples or support for any custom queries, you can find lots of topics in our #Data & reporting category under the #sql-query tag. If there’s not one to suit your pa…
