# Need some Help with my Triggered Custom Badge Query

**URL:** https://meta.discourse.org/t/need-some-help-with-my-triggered-custom-badge-query/395115
**Category:** Support
**Tags:** sql-triggered-badge
**Created:** [February 4, 2026, 6:47am UTC](https://meta.discourse.org/t/need-some-help-with-my-triggered-custom-badge-query/395115 "2026-02-04T06:47:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bisley](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@bisley](https://meta.discourse.org/u/bisley)
#### Post date: [February 4, 2026, 6:47am UTC](https://meta.discourse.org/t/need-some-help-with-my-triggered-custom-badge-query/395115/1 "2026-02-04T06:47:27Z")

</div>

Hi folks,  
I’m stuck on my SQL query. My goal / expectation is that it should grant a specific custom badge immediately when a user replies to a particular topic. The thing is I’m halfway there because the Daily “Backfill” job succeeds though the more immediate effect is clearly not working.

Our forum leverages the badge to provide access other categories (with some help from the automation plugin) so the End of Day/Backfill lag is pretty disorientating for the new users and definitely kills some momentum and enthusiasm upon joining up.

I’ve been ignoring the issue for a while I’m ready to break down and ask for some help.

I essentially lifted the query from the excellent post [Creating triggered custom badge queries](https://meta.discourse.org/t/creating-triggered-custom-badge-queries/19336) so it will probably look pretty familiar to most people.

```sql
SELECT p.user_id, p.id post_id, p.created_at granted_at
FROM badge_posts p
WHERE p.topic_id = 11558
AND (:backfill OR p.id IN (:post_ids) )

```

or I’ve also tried

```sql
SELECT
DISTINCT ON (p.user_id)
p.user_id, p.id post_id, p.created_at granted_at
FROM badge_posts p
WHERE p.topic_id = 11558 
AND(:backfill OR p.id IN (:post_ids) )

```

Both work for the EOD backfill but lack the promptness I’m expecting.

Here is a screenshot of the settings as currently set on the badge.

 ![Screen Snippet of the bottom Discourse Badge Settings. Run Revocation Query Daily (optional) is Checked. Query targets posts (optional) is checked. The badge is also allowed to be used as a title and granted multiple times - both options are checked. All the badge visibility settings are checked also. The badge's trigger is "When a user acts on post" and the Badge is part of the Getting Started group.](https://global.discourse-cdn.com/meta/original/4X/e/5/7/e57c0087c4731fa070b31e7dfb6a77310ff25ed7.png)

When I check the error logs I see some Backfill failure logs from when I first implemented the query but I don’t see any logs regarding the query failing when a user posts.

I’m probably just missing something obvious but I’ve squinted myself blind at this point so hopefully one of you will take pity on me and give me some pointers… or at least point me at some helpful documentation.

Thanks in advance!

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [February 4, 2026, 8:04am UTC](https://meta.discourse.org/t/need-some-help-with-my-triggered-custom-badge-query/395115/2 "2026-02-04T08:04:51Z")

</div>

Haven’t tested yet, but I think the trigger should be **“When a user edits or creates a post”**?

I think the one you have now = it fires on likes, flags, bookmarks, etc., not on post creation.

Edit: tested it now and it works for me 🙂

---

<div class="post-metadata">

### Author: ![bisley](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@bisley](https://meta.discourse.org/u/bisley)
#### Post date: [February 4, 2026, 9:10pm UTC](https://meta.discourse.org/t/need-some-help-with-my-triggered-custom-badge-query/395115/3 "2026-02-04T21:10:45Z")

</div>

oooohhhh. I thought I’d tried all the permutations of those settings. But I just tested and that was it! You’ve sorted me out!

So many months of playing the proverbial ostrich with my head in the sand and it was such a simple fix!

What a fantastic experience this has been.

Thanks @chapoi

\_\_\_\_

For posterity… this was the fix.

 ![Badge edit window is open and the Trigger dropdown is open. the mouse is hovering over the first option which reads "When a user edits or creates a post"](https://global.discourse-cdn.com/meta/original/4X/7/5/d/75d00d0182ccbb1c7dc4e472988d788db80f826e.png)

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [February 5, 2026, 9:15am UTC](https://meta.discourse.org/t/need-some-help-with-my-triggered-custom-badge-query/395115/4 "2026-02-05T09:15:24Z")

</div>

Hehe, you’re very welcome!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 7, 2026, 9:15am UTC](https://meta.discourse.org/t/need-some-help-with-my-triggered-custom-badge-query/395115/5 "2026-03-07T09:15:26Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
