I have a custom post type, let’s say ‘Book’, and I would like to creare it from scratch using API, including setting all the custom ACF fields associated with the Book type.
Which is the right approach?
Could do something like:
/*
* Create a new post and add field data
* - if the post does not already contain a "reference" to the field object, you must use the field_key instead of the field_name.
*/
// Create post object
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1
);
// Insert the post into the database
$post_id = wp_insert_post( $my_post );
// Add field value
update_field( "field_5039a99716d1d", "I am a value!", $post_id );
Snippet from: http://www.advancedcustomfields.com/resources/update_field/