I've got a Gravity Form that creates my custom post type after submission. I have a field group set up with custom fields that I'd like to populate based on values from the Gravity Form after submission and the new post is created.
I've got the following code in place, however I'm not sure what else I need. Is there a way that I can simply map the fields from Gravity Forms over to the Meta Box custom fields so I don't have to do each individually in code?
function update_meta_box_custom_fields( $post_id, $feed, $entry, $form ) {
// Get value from form
$value = '';
foreach ( $form['fields'] as &$field ) {
if ( $field->id == 40 ) {
$value = $field->value;
}
}
$data = [
'text_07vqcymyr6iw' => $value,
];
\MetaBox\CustomTable\API::add( $post_id, $table, $data );
}
// Gravity Form #4
add_action( 'gform_advancedpostcreation_post_after_creation_4', 'update_meta_box_custom_fields', 10, 4 );