1

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.

1 Answer 1

2

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.

4
  • 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, 2011 at 15:39
  • @t31os - agreed, that's what I'm using
    – anu
    Feb 2, 2011 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, 2011 at 15:51
  • ah - forget to vote him up..done now!
    – anu
    Feb 2, 2011 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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