I'm trying to figure out a problem I have.

I need to prevent my users from commenting on a post after that post received 15 numbers of comments. In a way I want to set the maximum number of comments a post can get. After that number is reached, I want the comments to be disabled for the posts. so when a post has 14 comments, I want the comment section to be open, after 15 comments , I want the comment section will be disabled. I tried the code below but couldnt get it work.

add_filter( 'init', 'manage_comment');

function manage_comment()
 global $post;

if ( ! $post ) {
    $count = 2; }
 add_filter( 'comments_open', '__return_false' );

I can't understand what I'm doing wrong. I'd really appreciate If someone could help me. Thank you in advance.Cheers

Your Answer

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

Browse other questions tagged or ask your own question.