Fixed on my own:
WITH summary as (
SELECT
t.id as topic_id,
t.created_at as created_at,
t.user_id as user_id,
COUNT (DISTINCT p.created_at::date) as num_days,
SUM (p.word_count) as num_words,
SUM (
length(raw) * 2
- length(replace(raw, '![IMG', '1234'))
- length(replace(raw, '[img]', '1234'))
) as num_images
FROM topics t
LEFT JOIN posts p ON p.topic_id = t.id
WHERE
t.category_id = 17
AND t.archived = false
AND t.closed = false
AND t.visible = true
AND p.deleted_at IS NULL
AND p.user_id = t.user_id
GROUP BY t.id
)
SELECT s.*,
CURRENT_DATE as granted_at
FROM summary s
WHERE
num_days >= 10
AND num_words >= 1000
AND num_images >= 10
ORDER BY created_at DESC