Support

Account

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/