I’m looking for a way to modify all posts of a certain category to be “no comments allowed” without going into each post settings, one by one, and modifying manually.
Perhaps a MySQL statement?
Thanks
I’m looking for a way to modify all posts of a certain category to be “no comments allowed” without going into each post settings, one by one, and modifying manually.
Perhaps a MySQL statement?
Thanks
You must be logged in to post a comment.
On your posts screen, you should be able to filter by category and then select all and bulk edit to turn off comments.
Edit: Bulk actions only apply per page (e.g. 20 posts or however many you have showing), so you’ll either have to do it for each page of results or go up to screen options and increase the number of items that are showing on screen.
To do it in WordPress directly you could use the following:
get_posts() will retrieve all of the posts with the category specified in $args by:
wp_insert_post() will allow you to modify said posts to disable comments with the following setting:
You may wish to view the documentation pages for get_posts() and wp_insert_post() for more information.
To ensure that no future posts under this category allow comments you could also use the save_post hook:
get_the_category() will retrieve the category object for the selected post. Visiting the documentation is a good idea for more information on get_the_category().
If you don’t know what an action hook is, you should visit this page.