将内容保存到自定义域(_C)

时间:2018-04-09 作者:bpy

是否可以保存内容(在WP WYSIWYG内(the_content)) 进入自定义字段?

This is what I have so far:

add_action(\'edit_post\', \'save_content_to_field\');
function save_content_to_field($post_ID) {
    global $wpdb;

    if(!wp_is_post_revision($post_ID)) {
        $content = get_the_content($post_ID);
        add_post_meta($post_ID, \'desc\', $content, true);
    }
}

2 个回复
最合适的回答,由SO网友:bpy 整理而成

好啊

我找到了这种方法,这可能对某些人有用:

add_action(\'edit_post\', \'save_content_to_field\');
function save_content_to_field($post_ID) {
    global $wpdb;

    if(!wp_is_post_revision($post_ID)) {
        //$content = get_the_content($post_ID);
        global $post;
        $content = apply_filters(\'the_content\', $post->post_content);

        add_post_meta($post_ID, \'desc\', $content, true);
       }
     }

SO网友:Mostafa Soufi

您可以使用$_REQUEST, 请尝试以下代码:

add_action(\'publish_post\', \'save_content_to_field\');
function save_content_to_field($post_ID) {
    if(isset($_REQUEST[\'content\'])) {
        update_post_meta($post_ID, \'desc\', $_REQUEST[\'content\']);
    }
}
UPDATED如果您想使用快捷代码支持,请使用以下代码:

add_action(\'publish_post\', \'save_content_to_field\');
function save_content_to_field($post_ID) {
    $post = get_post($post_ID);
    $result = apply_filters(\'the_content\',$post->post_content);

    if($result) {
        update_post_meta($post_ID, \'desc\', $result);
    }
}

结束

相关推荐