我想做两件事。对于特定的帖子类型,我希望有一个默认文本。我可以使用此代码执行以下操作:
add_filter( \'default_content\', \'my_editor_content\', 10, 2 );
function my_editor_content( $content, $post ) {
    switch( $post->post_type ) {
        case \'posttypehere\':
            $content = \'mydefaultposttextgoeshere\';
    }
    return $content;
}
 这很好,我可以看到文本并将其保存到数据库中。但是现在我想完全禁用这个特定帖子类型的文本框。我可以使用此代码执行以下操作:
add_action(\'init\', \'init_remove_support\',100);
function init_remove_support(){
    $post_type = \'posttypehere\';
    remove_post_type_support( $post_type, \'editor\');
}
 这将禁用文本框。
但现在的问题是,当我发布帖子时,默认文本不会保存到帖子中。那么,我如何实现这两个目标呢?
非常感谢。
 
                    最合适的回答,由SO网友:Johansson 整理而成
                    您可以手动挂接到save_post 保存时操作并更新帖子内容。下面是一段简单的代码:
add_action( \'save_post\', \'update_post_content\' );
function update_post_content($post_id) {
    // If this is a revision, get real post ID
    if ( $parent_id = wp_is_post_revision( $post_id ) ) {
        $post_id = $parent_id;
    }
    // Get the current post type
    $post_type = get_post_type($post_id);
    // Check if it\'s a custom post type
    if ( \'posttypehere\' != $post_type ) return;
    // unhook this function so it doesn\'t loop infinitely
    remove_action( \'save_post\', \'update_post_content\' );
    // update the post, which calls save_post again
    wp_update_post( 
        array( 
            \'ID\'            => $post_id, 
            \'post_content\'  => \'content here\' 
        ) 
    );
    // re-hook this function
    add_action( \'save_post\', \'update_post_content\' );
}