WordPress: How to display posts that have at least one comment? (2 posts)

  1. babyboy808
    Posted 5 years ago #

    I have been pulling my hair out for the past 3 hours!!

    Does anybody have any idea on how to show posts in wordpress that have at least one comment?

    The below code uses orderby=comment_count and it does work, but it still display other posts that have no comments too :(

    <?php $home_loop= new WP_Query("cat=-182,-183&showposts=10&paged=$paged&orderby=comment_count&order=DESC"); ?>

  2. vtxyzzy
    Posted 5 years ago #

    This code worked in my test site:

    function mam_posts_where ($where) {
       global $mam_global_where;
       if ($mam_global_where) $where = "$where $mam_global_where";
       return $where;
    $mam_global_where = "AND $wpdb->posts.comment_count > 0";
    $paged = (isset($_GET['paged'])) ? intval($_GET['paged']) : 1;
    $hl= new WP_Query("caller_get_posts=1&cat=-182,-183&showposts=10&paged=$paged&orderby=comment_count&order=DESC");
    if ($hl->have_posts()) : while ($hl->have_posts()) : $hl->the_post();
       echo '<br />';the_title();echo " - $post->comment_count";
    endwhile; endif;

Topic Closed

This topic has been closed to new replies.

About this Topic