I'm trying to make a page that will show only the posts that have comments. I have this in my page template:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( 'cat=-8378, -13444&orderby=comment_count&paged=' . $paged );
while (have_posts()) : the_post();

But it's not working. It still just shows my normal post display. Any suggestions?


  • To show code from something like a page template please use pastebin or another code pasting service. – Rachel Baker Aug 2 '12 at 1:09
  • @RachelBaker A question should be understandable without any external resource. – fuxia Aug 2 '12 at 2:31
  • @tosco When I first viewed the post the code snippet was not there at all. I assumed he was pasting in the entire page template. – Rachel Baker Aug 2 '12 at 15:15

your query doesn't restrict posts without comments.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( 'cat=-8378, -13444&orderby=comment_count&paged=' . $paged );
    while (have_posts()) : 
      if(  get_comments_number() ) the_post();


reference: get_comments_number()

  • Um...okay, so how can I get it to restrict posts without comments? – Ben Aug 2 '12 at 23:10
  • just like in the code i showed you. relevant code: if( get_comments_number() ) the_post(); – pcarvalho Aug 3 '12 at 0:52
  • Oh, I'm sorry, stupid me. I misread that code as simply a quote of mine. Thanks, I'll give it a try! – Ben Aug 3 '12 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.