Support

Account

Home Forums Front-end Issues ACF Load Post – Flexible Content – Not showing up on front end until manual save Reply To: ACF Load Post – Flexible Content – Not showing up on front end until manual save

  • Just as a follow-up. Was able to create a new post on a user registration and pre-pop the flexible layout and data with update field. Here is the code I added to my functions.php file for any one else looking:

    
    function create_new_user_posts($user_id){
    // Create new post.
        $post_data = array(
        'post_title' => 'New Post Title',
        'post_type' => 'Custom Post Name',
        'post_status' => 'publish',
        'post_author' => $user_id,
        );
        //Insert the post into the database
        $post_id = wp_insert_post( $post_data );
    
        // Save a flexible content field value.
        $field_key = "field_5eb8736d02e62";
        $value = array(
            array(
            'acf_fc_layout' => 'layout_1',
            'field_5eb873ab02e63' => 'This is what I want the field to say'
            ),
            array(
            'acf_fc_layout' => 'layout_2',
            'field_5eb8743702e68' => 'Starting 2 text'
            )
        );
        update_field( $field_key, $value, $post_id);
    }
    add_action('user_register','create_new_user_posts');
    

    Thank you for your help. Pushed me in the right direction.