# Badge for posting image in specific topic

**URL:** <https://meta.discourse.org/t/badge-for-posting-image-in-specific-topic/46960>\
**Category:** Development\
**Created:** [July 7, 2016, 5:26pm UTC](https://meta.discourse.org/t/badge-for-posting-image-in-specific-topic/46960 "2016-07-07T17:26:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![JoeZ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joez/32/65938_2.png) [@JoeZ](https://meta.discourse.org/u/JoeZ)\
**Post date:** [July 8, 2016, 7:36am UTC](https://meta.discourse.org/t/badge-for-posting-image-in-specific-topic/46960/2 "2016-07-08T07:36:49Z")

</div>

Please proof my work…I installed [Data Explorer](https://github.com/discourse/discourse-data-explorer) which dramatically helped me understand the database structure as well as the ability to try out some queries. From what I can tell, this will pull if you have uploaded an image to a specific topic.

set topic\_id (6th line) as the topic for the badge.

```
SELECT DISTINCT ON (sub.user_id)
sub.user_id, sub.post_id, sub.created_at granted_at from (SELECT p.created_at, p.user_id, p.id as post_id,
    length(raw) * 2
      - length(replace(raw, '<img', '123'))
      - length(replace(raw, '[img]', '1234')) as num
  FROM posts p where topic_id=62) sub
  where sub.num > 0 AND (:backfill OR sub.post_id IN (:post_ids) )

```

Updated. Needed to have the ‘granted\_at’ as well as post\_ids

---

_[View the full topic](https://meta.discourse.org/t/badge-for-posting-image-in-specific-topic/46960)._
