2

This question already has an answer here:

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.

marked as duplicate by Nathan Johnson, Community Mar 7 '18 at 17:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

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.