WordPress: get posts with zero comments and specific tags?

Does anyone have an idea of how to get posts that have no comments yet and have specific tags?

I tried

Read More
$args = array(
        'tag' => $tags,
        'post__not_in' => array($page_id),
        'showposts'=>5,
        'ignore_sticky_posts'=>1,
        'comment_count' => 0
);

 $my_query = new WP_Query($args);
 if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          ... the usual stuff here ...
        endwhile;
}

but this gives me also the posts that were already commented even if there’s a “‘comment_count’ => 0” argument! Why? What’s the right solution?

Thanks.

Related posts

Leave a Reply

2 comments

  1. The comment_count parameter is part of the orderby parameters. Basically you can specify that posts should be ordered by comment count (either ascending or descending but this will display all posts just either starting with the least (or most) comments.

    There doesn’t currently seem to be an ‘out-of-the-box’ solution for only displaying posts with no comments but this question deals with it pretty well:

    WordPress: List posts with no comments

    Given that you want to display posts with certain tags as well you’ll want to modify the custom query a bit and specify which tags to include. Check out this article for the codex for some ideas on how to do that:

    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query#Query_based_on_Custom_Field_and_Category

  2. I figured out that after using Wp_Query() you get an object that holds your query … so if you copy paste it into your php code and add a wp_posts.comment_count=0 condition in the WHERE clause it works perfectly!