title: Only return posts with comments in Wordpress
body: <p>I'm surprised I cannot find much on this topic, perhaps I'm confused.</p>
  
  <p>I am creating an archive page of comments. I want to get all posts with comments where I will list the post title followed by the all the comments for that post underneath using wp_list_comments or WP Comment Query.</p>
  
  <p>My question is how can I filter WP_Query() so I can only return posts that have comments.</p>
  
  <p>I've tried to modify this approach <a href="https://stackoverflow.com/questions/4829733/wordpress-list-posts-with-no-comments">list posts with no comments</a> - postpostmodern's answer but I want to do the exact opposite.</p>
  
  <p>Here is the function:</p>
  
  <pre><code>function filter_comment_count( $sql ){
      global $wpdb;
      $comment_count = get_query_var( 'comment_count' );
  
      if( is_numeric($comment_count) )
          $sql .= $wpdb-&gt;prepare( " AND {$wpdb-&gt;posts}.comment_count != %d ", $comment_count);
  
      return $sql;
      }
  add_filter( 'posts_where', 'filter_comment_count'  );
  </code></pre>
  
  <p>And then I'm attempting to use it in my loop, here is an excerpt:</p>
  
  <pre><code>$args = array (
      'comment_count'  =&gt; '0'
      'pagination'     =&gt; true,
      'posts_per_page' =&gt; '10',
  );
  
  $the_query = new WP_Query($args); 
      while($the_query-&gt;have_posts()) : $the_query-&gt;the_post();  
          get_template_part( 'content', get_post_format() );
      endwhile;
  wp_reset_postdata();
  </code></pre>
  
  <p>I guess the bit that is tripping me up is <code>AND {$wpdb-&gt;posts}.comment_count != %d</code> I want it to return <code>comment_count</code> not equal to 0 or whatever allows me to get only posts with comments in my <code>WP_Query($args);</code> </p>
  
  <p>Also I'm not sure where to put <code>remove_filter( 'posts_where', 'filter_comment_count' );</code>?</p>
  
  <p>I realise there is <code>'orderby' =&gt; 'comment_count'</code> but that doesn't exactly help my situation as far as I understand.</p>