Can’t set Post ID properly

Question

I’m trying to generate posts based on a JSON document. I’m stuck at the trying to assign the ID from the json document to the post’s wordpress ID. I read on here that the way of going about this is though setting an ‘import_id’ on wp_insert_post

$json = json_decode("{
        "tt1412213":{
           "title":"Movie",
           "rating":"excellent"
        }
    }", true);

foreach($json as $item) { 
    $itemID = array_keys($filmJson, $item);
    if (get_post_status( $itemID ) == false ) {
        if($item["title"] and $item["rating"]){
            global $user_ID;
            wp_insert_post(array(
                'post_title' => $item["title"],
                'post_content' => $item["rating"],
                'post_status' => 'publish',
                'post_date' => date('Y-m-d H:i:s'),
                'post_author' => $user_ID,
                'post_type' => 'post',
                'post_category' => array(0),
                'import_id' => $itemID
            ));
        }
    }
}

I would like my post to have the ID tt1412213 but it defaults to a number instead. Anything I’m missing?

0
Fluxian 1 week 2021-09-09T09:52:50-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse