Home › Forums › ACF PRO › How to creare a post programatically? › Reply To: How to creare a post programatically?
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/
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.