Original query:

explain analyze select images.* from images 
join locations on locations.id = images.location_id
join users on users.id = images.creator_id
WHERE images.creator_id = ANY(array(select users.id FROM users join user_groups on user_groups.user_id = users.id WHERE user_groups.group_id = 967))
AND images.deleted_at IS NULL
AND images.status = 2
AND images.creator_type = 'User'
AND locations.active = true
ORDER BY date_uploaded DESC
limit 50;