Set post comments open function

I’ve been searching high and low for a php function to set a comments of a given postID open

only found function to check what the comment status is

<?php comments_open( $post_id ); ?>

I need one to set comment would expect it to be

<?php set_comments_open( $post_id ); ?>

But it isnt anybody got any idea what the function is or if there isnt one how to do it?

4 Answers
4

Have you tried go to Posts and checked the box next to the title and in the dropdown “Bulk Actions” choose Edit and then apply, Comments and in the dropdown “Allow”.

And also have added the screen in the post edit area on the tab in the header called “Screen Options” and checked the field called: Discussion?

And in Settings->Discussion have you enabled “Allow people to post comments on new articles”?

Add comments open to all posts

A filter hook called by the wp_insert_post function prior to inserting into or updating the database and update the post comment_status to open = true

function comments_on( $data ) {
    if( $data['post_type'] == 'post' ) {
        $data['comment_status'] = 1;
    }

    return $data;
}
add_filter( 'wp_insert_post_data', 'comments_on' );

Leave a Comment