默认情况下允许对多个帖子类型发表评论

时间:2019-01-28 作者:Andrew

我有一个职位类型的工作,但需要做三个。我尝试了“else”语句,但我意识到我在PHP方面很差劲。

function my_comments_open( $open, $post_id ) {

$post = get_post( $post_id );

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

return $open;

}

1 个回复
SO网友:Zeshan
function default_comments_on( $data ) 
{
    $myCustomPostType = array("my_custom_post_type_1", "my_custom_post_type_2", "contacts"); /* Custom Post Type Array */

    if (in_array($data[\'post_type\'], $myCustomPostType))
    {
        $data[\'comment_status\'] = \'open\';
    } 

    return $data;
}
add_filter( \'wp_insert_post_data\', \'default_comments_on\' );

Add this code in functions.php