$postType, 'post_status' => 'publish', 'post_title' => $postTitle, 'post_content' => $postContent, ); $postId = wp_insert_post($postData); foreach($fields as $field) { af_save_field($field['name'], $postId); } } function afprocs_settings_fields($settings_field_group) { $tabField = array ( 'key' => 'field_form_processors_tab', 'label' => 'Processors', 'name' => '', 'type' => 'tab', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ('width' => '', 'class' => '', 'id' => ''), 'placement' => 'left', 'endpoint' => 0 ); $processorsField = array ( 'key' => 'field_form_processors', 'label' => 'Processors', 'name' => 'processors', 'type' => 'flexible_content', 'value' => NULL, 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'hide_admin' => 0, 'layouts' => array ( '59ffdca45db00' => array ( 'key' => '59ffdca45db00', 'name' => 'create_post', 'label' => 'Create Post', 'display' => 'block', 'sub_fields' => array ( array ( 'key' => 'field_59ffdcc35db01', 'label' => 'Post Type', 'name' => 'post_type', 'type' => 'posttype_select', 'value' => NULL, 'instructions' => 'The type of post to create', 'required' => 1, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'hide_admin' => 0, 'default_value' => '', 'allow_null' => 0, 'multiple' => 0, 'placeholder' => '', 'disabled' => 0, 'readonly' => 0, ), ), 'min' => '', 'max' => '', ), '59deb5ec2e21a' => array ( 'key' => '59deb5ec2e21a', 'name' => 'redirect', 'label' => 'Redirect', 'display' => 'block', 'sub_fields' => array ( array ( 'key' => 'field_59deb64539d86', 'label' => 'URL', 'name' => 'url', 'type' => 'url', 'value' => NULL, 'instructions' => 'Redirect users to a URL once the form has been successfully submitted', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'hide_admin' => 0, 'default_value' => '', 'placeholder' => 'https://www.mysite.com/thank-you/', ), ), 'min' => '', 'max' => '', ), ), 'button_label' => 'Add Processor', 'min' => '', 'max' => '' ); array_push($settings_field_group['fields'], $tabField, $processorsField); return $settings_field_group; }