Search / Watching for Tags only populates Topics with the tag, not replies

You can reference a tag in a post, but only a topic can actually be tagged as such.

However, if you have the data explorer plugin you could use a query something like this to pull up a list of ones where the tag has been linked in a post:

-- [params]
-- string :hashtag
-- date :start_date
-- date :end_date 

WITH target_posts AS (
  SELECT 
    p.id AS post_id,
    t.category_id,
    p.created_at
  FROM posts p
  JOIN topics t ON p.topic_id = t.id
  JOIN users u ON u.id = p.user_id
  WHERE t.deleted_at IS NULL
    AND t.archetype = 'regular'
    AND p.deleted_at IS NULL
    AND p.post_type = 1
    AND p.created_at::date BETWEEN :start_date AND :end_date
    AND p.post_number <> 1
)

SELECT
  tp.category_id,
  tp.post_id,
  tp.created_at::date
FROM target_posts tp
LEFT JOIN post_search_data psd ON psd.post_id = tp.post_id
WHERE psd.search_data @@ TO_TSQUERY(:hashtag)
ORDER BY tp.created_at DESC

4 Likes