我正在尝试通过RESTAPI导入post meta。我在父站点上设置了元值,但当我将帖子导入子站点时,会在值中添加其他字符。
下面是父站点的post meta的JSON表示:
"post-meta-fields": {
"_edit_lock": [
"1498250457:1"
],
"_edit_last": [
"1"
],
"color": [
"#4298f4"
],
"_thumbnail_id": [
"6"
]
},
下面是导入到子站点后的元数据:
"post-meta-fields": {
"city_name": [
"city_Columbus"
],
"import": [
"import"
],
"color": [
"a:1:{i:0;s:7:\\"#4298f4\\";}"
]
}
最后,这里是我用来导入的cod:
function create_import_post_from_url($url, $post_args, $city_name ) {
$post_url = file_get_contents($url);
$post_data = json_decode($post_url, true);
foreach($post_data as $article_array ) {
$title = $article_array[\'title\'][\'rendered\'];
if (!post_exists($title) ){
if( empty($post_args)) {
$post_args = array(
\'post_author\' => $article_array[\'author\'],
\'post_content\' => $article_array[\'content\'][\'rendered\'],
\'post_content_filtered\' => \'\',
\'post_title\' => $article_array[\'title\'][\'rendered\'],
\'post_excerpt\' => $article_array[\'excerpt\'][\'rendered\'],
\'post_status\' => $article_array[\'status\'],
\'post_type\' => $article_array[\'type\'],
\'comment_status\' => $article_array[\'comment_status\'],
\'ping_status\' => $article_array[\'ping_status\'],
\'post_password\' =>$article_array[\'post_password\'],
\'to_ping\' => $article_array[\'to_ping\'],
\'pinged\' => $article_array[\'pinged\'],
\'post_parent\' => $article_array[\'post_parent\'],
\'menu_order\' => $article_array[\'menu_order\'],
\'guid\' => $article_array[\'guid\'][\'rendered\'],
\'import_id\' => 0,
\'context\' => \'\',
\'meta_input\' => array(
\'city_name\' => $city_name,
\'import\' => \'import\',
\'color\' => $article_array[\'post-meta-fields\'][\'color\'],
)
);
}
wp_insert_post($post_args, $wp_error);
}
}
}
我一直无法在网上找到有关此问题的任何信息,因此非常感谢您的帮助!