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?
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 postcomment_status
to open = trueCame upon this one today. I don’t think the accepted answer here actually gets at what the OP is asking. He’s not having trouble with setting up a post to accept comments in the admin panel. He’s asking for a PHP function that can set a post’s ‘comment_status’ column.
I had a similar reason for looking: I’m updating content based on an import, so the answer here doesn’t help. The answer in the comments gives a way to do this when INSERTING a post, but not a good way to update. And I don’t see a WP function that exists to do this – had to write one:
Seems like something that should exist. Hopefully that helps someone.
You can add code like this
$post->ID
is post id which you already haveIf you need to allow comments on a post that have already had them disabled, you will need to change the column for
comment_status
of that post toopen
.As JBoss has shown, you can do this through a wpdb statement, however you can also just make use of the native WordPress post updating function:
wp_insert_post
If you need to loop through all of your posts to do this you can make use of a normal
WP_Query
to do it like this: