• Hi everyone,

    I’m writing a script to display popular posts on my site by comment count, but I want to exclude any posts whose comments are closed (ie old contests with thousands of comments, but no longer active).

    Here’s the code I’m using now: https://wordpress.pastebin.com/m9KGLWxR

    Is there any way to modify the get_posts query so that it excludes any posts whose comments have been closed?

    Thanks!

    Matt

Viewing 1 replies (of 1 total)
  • You could use a filter to add a ‘where’ condition. However, if you just want to skip those posts, add a test for comment_status like this:

    foreach($popular as $post) :
    			setup_postdata($post);
    			$count++;
    			if ($post->comment_status != 'open') continue;
    	?>
Viewing 1 replies (of 1 total)
  • The topic ‘In get_posts, exclude posts where comments are closed?’ is closed to new replies.