WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
The answer provided by postpostmodern on the SO topic was a good approach, i'm surprised it wasn't the accepted answer(far less fiddly then the SQL approach). – t31os Feb 2 '11 at 15:39
@t31os - agreed, that's what I'm using – anu Feb 2 '11 at 15:44
You know, this might make a valid feature request to, though it could be handled by a plugin, i can think of several reasons being able to select posts based on comment count might be useful. Be sure to sling a vote onto postpostmodern's answer if you're registered on SO(note: you can use the account you have here on SO to, it just won't carry across the rep)... ;) – t31os Feb 2 '11 at 15:51
ah - forget to vote him up..done now! – anu Feb 2 '11 at 16:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.