Custom badge query is not targeting posts

Hi everyone,

I’m running Discourse v2.2.0.beta6 +5 and seem to be having an issue when trying to link specific posts to a new badge, automatically.

I have created a badge called “Pin Seeker” and here’s a screen shot of the current settings for that badge:

The following SQL is used to automatically issue the badge daily:

SELECT p.user_id, min(p.created_at) granted_at, MIN( post_id
FROM badge_posts p
JOIN topics t ON = p.topic_id
WHERE category_id = (
  SELECT id FROM categories WHERE name ilike 'Where to fly your drone in the UK'
) AND p.post_number = 1 AND p.raw LIKE '' 
GROUP BY p.user_id

So when someone starts a new topic in the category called “Where to fly your drone in the UK” and that topic also contains a link to then we grant them the Pin Seeker badge.

This query works fine and the badge gets issued to the correct people each night :+1:t2:

However, when viewing the badge itself, or the profile of people with the badge, there is no link to their topic.

Despite me ticking the “Query targets posts” check box (as you’ll see above). Other badges show the links correctly so this is not a site-wide issue.


The strange thing is that when I click on “Preview granted badges” the links to the topic appear correctly in the preview:


Anyone come across this issue before?

Have I missed something in my badge SQL that ‘makes’ the links to the topics? :thinking:


I’ve just solved my own issue.

I’d missed this check box!

Sorry :blush:


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