For a custom post type I have enabled support for comments via php and CPT.

    'supports' => array(

But each post still has its "Allow comments" box in the discussion-field unchecked. I am now looking for a way to automatically check this box, as I have quite a big number posts of this custom post type and do not think, this can only be done manually.

However, I have other custom post types where I still want comments to be disabled. So I am looking for a way, to check all "enable comments" for one specific post type.


This answer here fixed it for me: https://wordpress.stackexchange.com/a/243732/138177

add_filter( 'comments_open', 'my_comments_open', 10, 2 );

function my_comments_open( $open, $post_id ) {

  $post = get_post( $post_id );

  if ( 'myCustomPostType' == $post->post_type )
      $open = true;

  return $open;

Not the answer you're looking for? Browse other questions tagged or ask your own question.