gpt4 book ai didi

mysql - 将 WordPress 自定义帖子类型内容移至自定义字段值

转载 作者:行者123 更新时间:2023-11-30 01:02:39 24 4
gpt4 key购买 nike

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

谢谢!

最佳答案

您可以将类似的内容(未经测试)放入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 运行更新

关于mysql - 将 WordPress 自定义帖子类型内容移至自定义字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19967768/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com