# Get Post Id's of posts that a user liked

**URL:** https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074
**Category:** Development
**Created:** [March 28, 2018, 10:43pm UTC](https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074 "2018-03-28T22:43:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rodeezy](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@rodeezy](https://meta.discourse.org/u/rodeezy)
#### Post date: [March 28, 2018, 10:43pm UTC](https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074/1 "2018-03-28T22:43:15Z")

</div>

I would like to get the id’s of posts that a specific user has liked. How can I do this?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 28, 2018, 11:04pm UTC](https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074/2 "2018-03-28T23:04:54Z")

</div>

You can find that with the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) Plugin with a query like this:

```plaintext
-- [params]
-- string :username

WITH sample_user AS (
SELECT
u.id
FROM users u
WHERE u.username = :username
)

SELECT
p.topic_id,
pa.post_id,
pa.created_at AS liked_at
FROM post_actions pa
JOIN posts p
ON p.id = pa.post_id
WHERE pa.post_action_type_id = 2
AND pa.user_id = (SELECT id FROM sample_user)
ORDER BY pa.created_at DESC

```

If you need to see the actual `id`, instead of a link to the topic and an excerpt of the post, change the line

```plaintext
pa.post_id

```

to

```plaintext
pa.post_id AS id

```

To get the post\_ids with an ActiveRecord query, do something like this, with the `user_id` of the user you are looking for:

```plaintext
PostAction.where(post_action_type_id: 2, user_id: 1).pluck(:post_id)

```

---

<div class="post-metadata">

### Author: ![rodeezy](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@rodeezy](https://meta.discourse.org/u/rodeezy)
#### Post date: [March 28, 2018, 11:54pm UTC](https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074/3 "2018-03-28T23:54:24Z")

</div>

this looks really cool!

---

<div class="post-metadata">

### Author: ![rodeezy](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@rodeezy](https://meta.discourse.org/u/rodeezy)
#### Post date: [March 28, 2018, 11:54pm UTC](https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074/4 "2018-03-28T23:54:46Z")

</div>

Specifically, I was wondering if there was a way to get this through api

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 29, 2018, 12:01am UTC](https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074/5 "2018-03-29T00:01:34Z")

</div>

> [@rodeezy](#):
>
> Specifically, I was wondering if there was a way to get this through api

You can query the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) through the API. Take a look at [Access to query data from API endpoints](https://meta.discourse.org/t/access-to-query-data-from-api-endpoints/90614).
