我没有找到任何解决方案来以自定义帖子类型将json数据导入自定义字段和自定义分类法。这是我的代码,用于导入json以使用此脚本制作wordpress自定义帖子。
$json = "http://tropiktv.ba/filmovi/raspored.json";
$response = file_get_contents($json);
$mydecode = json_decode($response);
for ($i = 0; $i < 1; $i++) {
$title = str_replace("&", "&", $mydecode[$i]->Naziv);
$description = str_replace("&", "&", $mydecode[$i]->Opis);
$coupon_type = 'filmovi';
$link = $mydecode[$i]->link;
$zanr = $mydecode[$i]->Žanr;
if( $coupon_type === "filmovi" ) {
// Check if already exists
$get_page = get_page_by_title( $title );
if ($get_page == NULL){
// Insert post
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'filmovi'
);
// Insert post
$post_id = wp_insert_post($new_post);
// Insert post meta if available
update_post_meta( $post_id, 'opis', $description );
update_post_meta( $post_id, 'link', $link );
update_post_meta( $post_id, 'inline_featured_image', 'http://tropiktv.ba/wp-content/uploads/mala-princeza.jpg' );
// Uncomment to check if meta key is added
// $get_meta_value = get_post_meta( $post_id, 'meta_key', true );
// echo "<pre>";
// print_r($get_meta_value);
}
}else{
// Update meta value
update_post_meta($get_page->ID, 'my_key', 'meta_value');
// Uncomment to check if meta key is added
// $get_meta_value = get_post_meta( $get_page->ID, 'meta_key', true );
// echo "<pre>";
// print_r($get_meta_value);
}
}