# Ottieni gli ID dei post che un utente ha messo mi piace

**URL:** <https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074>\
**Category:** Development\
**Created:** [28 Marzo 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:** 1\
**Showing post:** 2

<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:** [28 Marzo 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)

```

---

_[View the full topic](https://meta.discourse.org/t/get-post-ids-of-posts-that-a-user-liked/84074)._
