1

嘿,我有一个从 csv 文件导入自定义帖子类型的 163 个帖子,除了一个小问题外,这一切都很好。该插件迫使我将一列放入内容字段 - 所以我选择了一个我将作为自定义字段放入的列 - 我现在是否可以将它们全部转换为自定义字段并清除内容区域?

谢谢!

4

1 回答 1

0

你可以把这样的东西(未经测试)放入functions.php

add_action( 'get_header', 'so19967768_update_posts' );
function so19967768_update_posts()
{
    if( ! isset( $_GET['update'] ) )
        return;

    $posts = get_posts( array( 'post_type' => 'my_post_type', 'posts_per_page' => -1 ) );

    foreach( $posts as $post )
    {
        setup_postdata( $post );
        $value = $post->post_content;
        update_post_meta( $post->ID, 'my_meta_key', $value );
        wp_update_post( array(
            'ID' => $post->ID,
            'post_content' => ''
        ) );
    }

    echo 'update complete!';

    die();
}

并访问yoursite.com/?update=1以运行更新

于 2013-11-14T01:32:11.050 回答