babyboy808
Member
Posted 2 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"); ?>
This code worked in my test site:
<?php
function mam_posts_where ($where) {
global $mam_global_where;
if ($mam_global_where) $where = "$where $mam_global_where";
return $where;
}
add_filter('posts_where','mam_posts_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;
?>