XF 2.1 How can I update this post finder to return only one post per thread ID?

HJW

Active member
Hello,

I've got the finder query below to get the most popular posts. How would I adjust this so that only one post per thread ID was returned?

$postFinder = $this->finder('XF:Post');
$postFinder
->with(['Thread.Forum.Node.Permissions|' . $visitor->permission_combination_id, 'User'])
->where('Thread.discussion_state', 'visible')
->where('message_state','visible')
->where('reaction_score', '>', 0)
->setDefaultOrder('reaction_score', 'DESC')
->limit(max($limit * 2, 10));

thanks
 
Solution
Finder does not support "group by" yet so you will require to do a raw query to get post ids and then fetch posts using finder with those post ids.
Finder does not support "group by" yet so you will require to do a raw query to get post ids and then fetch posts using finder with those post ids.
 
  • Like
Reactions: HJW
Solution
Top Bottom