Filter custom posts with / without comments

I need to display (for pages that use a particular page template) a list of custom post type objects filtered into 2 sets – those with comments, and those without comments. Each of these sets should display the last 10 of its type (ie the latest 10 posts with comments, and the lastest 10 posts without comments)

What’s the best way of achieving this? So far, the easiest thing I’ve come up with is to just do a custom select with $wpdb. Hooking the query and adding a posts_join / posts_where filter doesn’t seem like the best answer, as it’s too global.

Related posts

Leave a Reply

1 comment

  1. And I should have done some searching before asking.

    Looks like hooking the query might be the best way of doing this. Here’s a good answer from StackOverflow with practically the same question.