0
votes

I have a page that displays certain posts from a certain category, in this case category 33:

  <?php $top_query = new WP_Query('cat=33'); ?>
  <?php while($top_query->have_posts()) : $top_query->the_post(); ?>

How Can I specify that the posts returned should only be ones that have comments enabled?. I have tried wrapping it in:

<?php if(comments_open()) : ?> 

Hover that needs to be used within the loop :(

Thanks in advance

1

1 Answers

0
votes

In the wordpress database the post status is saved in the $wpdb->posts table in the comment_status column. Try passing this variable to WP_Query also like this:

<?php $top_query = new WP_Query( array('cat'=>33, 'comment_status'=>'open'); ?>
<?php while($top_query->have_posts()) : $top_query->the_post(); ?>

this should do it.