I have managed to solve using the add_post_meta function instead of the meta_input
property of the $postarr
argument of the wp_insert_post function, as follows
Instead of this
$entry = [
"post_title" => "Some post title",
"post_content" => "Some post content",
"post_type" => "name_of_custom_post_type",
"post_status" => "publish",
"meta_input" => [
"some_meta_key" => "Some value",
"another_meta_key" => "Another value"
]
];
$post_id = wp_insert_post($entry, true);
I used this
$entry = [
"post_title" => "Some post title",
"post_content" => "Some post content",
"post_type" => "name_of_custom_post_type",
"post_status" => "publish",
];
$post_id = wp_insert_post($entry, true);
add_post_meta($post_id, "some_meta_key", "Some value");
add_post_meta($post_id, "another_meta_key", "Another value");
I do not understand the reason why it has not worked for me, when inspecting the result of $wp_error
I do not get an error, but as I have described in the question when using meta_input
no values are registered in postmeta
table