I have a plugin that automatically converts Contact Forms to Post. I made sure that all the posts submitted by this plugin contain a particular taxonomy.

Category: "Discussion nuggets". 

I would want to allow commenting for all posts with that category. What is the best way? Should I find a way to enable commenting when the form is converted to a post? That would mean looking carefully at the Plugin codes and modifying it or attaching a hook to it. Or I can just add a code to my function.php to update post with the categories discussion nuggets.

add_action( 'wp_insert_post', 'set_commenting_for_specific_taxonomy', 10, 2 );

function set_commenting_for_specific_taxonomy( $post_ID, $post )
  $categories = get_the_category($post_ID);
  if (in_array($categories, "Discussion nuggets")) {
     remove_filter(current_filter(), __FUNCTION__ );
     $post->comment_status = 'open';
     wp_update_post( $post );
  • I think you are on the right track (see this similar question/answer) however, you need to ensure that you have comments support enabled for your custom post type. – Aurovrata Aug 13 '20 at 8:45

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.