Home / Admin / Merging Multiple WPForms Field Values into Post Content
Duplicate Snippet

Embed Snippet on Your Site

Merging Multiple WPForms Field Values into Post Content

<10
Code Preview
php
<?php
/**
 * Merging Multiple WPForms Field Values into Post Content
 *
 * @link https://wpforms.com/developers/merging-multiple-wpforms-field-values-into-post-content
 */
function wpf_dev_post_submissions_process( $post_id, $fields, $form_data ) {
    // If form ID is 463, run code below
    if ( 463 !== absint( $form_data[ 'id' ] ) ) {
        return;
    }
    
// Get values from fields with IDs 2 and 3
$field_2_value = isset( $fields[2]['value'] ) ? $fields[2]['value'] : '';
$field_3_value = isset( $fields[3]['value'] ) ? $fields[3]['value'] : '';
// Update post content with the values from fields 2 and 3
$post_content = $field_2_value . ' ' . $field_3_value;
wp_update_post( array(
    'ID'           => $post_id,
    'post_content' => $post_content,
) );
}

Comments

Add a Comment