Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to query out only posts that have comments. So posts with comment_count = 0 won't show but anything above that will.

This is what i query but it still picks out posts that doesen't have comments. Is there another way?

query_posts(array('comment_count' > 0, 'post_type' => 'letters', 'showposts' => 10, 'post_status' => array('publish'), 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1), 'meta_key' => 'letter_show_on_site', 'meta_value' => "yes"));
share|improve this question
'comment_count' was not meant to filter posts in that manner. It was used by WP_Query only to order posts. –  sri Dec 6 '13 at 10:30
okay, thank you for the information. Is there any other way to pick out posts with comments? –  Paparappa Dec 6 '13 at 10:32

2 Answers 2

you can use WP_Query

$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
    'post_type' => 'letters',
    'posts_per_page' => 10,
    'paged' => $paged,
    'meta_key' => 'letter_show_on_site',
    'meta_value' => "yes"
$the_query = new WP_Query($args);
if( $the_query->have_posts()){
        global $post;

        //show post which have comment_count > 0
        if( 0 < $post->comment_count ){


share|improve this answer

By using the query below(not tested) you will be able to get all the ids of posts that have comments.

$postids = $wpdb->get_col("SELECT distinct ID FROM $wpdb->posts, $wpdb->comments where comment_post_ID = ID ORDER BY ID");
share|improve this answer

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.