# 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:** 2
**Page:** 1

<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 7, 2016, 5:26pm UTC](https://meta.discourse.org/t/badge-for-posting-image-in-specific-topic/46960/1 "2016-07-07T17:26:01Z")

</div>

I had an idea for a badge, one that’d work well for a site like @yetidragon [http://forum.combustionpunks.co.uk/badges](http://forum.combustionpunks.co.uk/badges)

Assume a car forum. In this forum, there is a set topic for different makes, like Honda, Toyota, etc. If a member posts a PHOTO in the specific topic for the make, they get a specific badge for their make. Just posting a text reply grants them nothing.

@meglio has a badge that most of the functionality is there, but I’m too green to modify it to work for this idea.

> [@"Personal Page" badge](https://meta.discourse.org/t/personal-page-badge/37721):
>
> I’d like to share a badge that I developed for a contest in [forum.kozovod.com](http://forum.kozovod.com). Personal Page badge Created a topic in a particular category Wrote at least 1000 words in the topic (in one or multiple messages) Wrote in the topic at least 10 days (non-consecutive) Uploaded at least 10 images Goal In our forum, we have a category named “farms”. Goat farmers, small to big, are welcome to create their own topic/page there to tell about their farm, upload photos, push news and answer questions from…

Thoughts?

---

<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
