Automatically check “Allow comments” for custom post type [duplicate]

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

    'supports' => array(
        'title',
        'editor',
        'revisions',
        'comments',
     )

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.

1 Answer
1

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;
}

Leave a Comment