I previously asked and accepted a similar question here: wp_query and comment_parent - select only posts with top level comments

So I'm trying to use wp_query to select only posts that have comments. The problem I'm facing now is I have numerous filters as part of an advanced search e.g. name, location (country, area), tags etc etc and it is becoming to difficult to select post ids in the method shown in the accepted answer. There are just to many possible combinations of searches and options.

Ideally I need a way to exclude posts without a comment globally, in one hit.

I was hoping for something nice and easy like:

 $args = array(
       'post_type' => 'films',
       'have_comments' => true

But I cant seem to find anything like that.

I thought maybe a filter in functions.php or with the use of have_comments() somehow? I dont really want to select all posts and hide in the have posts loop if I can help it as there could potentially be hundreds of rows returned in wp_query that are not needed.

Sorry, I'm a beginner at this so I'm not really sure of a way forward.

  • stackoverflow.com/questions/4829733/… - Look at the seconds answer, you just need to change the IF statement
    – passatgt
    Apr 1, 2013 at 11:08
  • Hi passatgt. Do you mean answer 1 "if(!empty($_GET['no_comments'])){"? if so, change it to what?
    – Chris
    Apr 1, 2013 at 11:24

1 Answer 1


You might try this:

add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query($args);
remove_filter( 'posts_where', 'filter_where' );


function filter_where( $where = '' ) {
    $where .= " AND comment_count > 0 ";
    return $where;

to get posts with comments.


Your Answer

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

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