wp_insert_post($post), add an array of values with update_post_meta

Question

i try to store an array in multiple custom fields via post creation (wp_insert_post).
The array is $event_test and the key is event_test on the meta_input.

On form submit, the custom field is shown, but its empty.

// Form to Post Quform
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {    

    // Default Post Data   
    $content = $form->getValue('quform_1_30'); 

    // Custom Fields from the form
    $event = $form->getValue('quform_1_3');
    $event_standort = $form->getValue('quform_1_4');
    $event_budget = $form->getValue('quform_1_5');
    $event_date = $form->getValueText('quform_1_9');
    $event_time_from = $form->getValue('quform_1_10');
    $event_time_to = $form->getValue('quform_1_11');
    $event_plz = $form->getValue('quform_1_25');
    $event_stadt = $form->getValue('quform_1_24');
    $event_gaeste = $form->getValue('quform_1_26');
    $event_musiker = $form->getValue('quform_1_31');
    $event_musikstil = $form->getValue('quform_1_21');
    $event_email = $form->getValue('quform_1_28');
    $event_test = array('Value1', 'Value2', 'Value3');


    // Store all custom Data in the Posts Array
    $post = array(
        'post_title' => $event . ' in ' . $event_standort . ' (' . $event_plz . ' ' . $event_stadt . ')',
        // 'post_content' => $content,
        'post_excerpt' => $content,
        'post_type' => 'events',
        'post_status' => 'publish',

        'meta_input' => array(                          
                            // Custom Fields
                            'event_budget' => $event_budget,
                            'event_date' => $event_date,
                            'event_date_timestamp' => strtotime($event_date),
                            'event_time_from' => $event_time_from,
                            'event_time_to' => $event_time_to,
                            'event_plz' => $event_plz,
                            'event_stadt' => $event_stadt,
                            'event_gaeste' => $event_gaeste,
                            'event_musikstil' => update_post_meta($post_id, "event_musikstil", $event_musikstil),
                            'event_email' => $event_email,
                            'event_test' => update_post_meta($post_id, "event_test", $event_test),

                            // Taxonomy Names
                            'event' => $event,
                            'event_standort' => $event_standort,
                            'event_musiker' => $event_musiker
                        )
    );


    // get the post id to insert post into taxonomies and insert all fields to the post (create the post)
    $post_id = wp_insert_post($post);



    // insert taxonomy values from form
    wp_set_post_terms( $post_id, $event, 'leweb_ct_event_musiker', true ); // set the taxonomy Event Musiker from form value
    wp_set_post_terms( $post_id, $event_standort, 'leweb_ct_standort', true ); // set the taxonomy Standort from form value
    wp_set_post_terms( $post_id, $event_musiker, 'leweb_ct_musiker', true ); // set the taxonomy Musiker from form value

    return $result;
}, 10, 2);
0
, , LovinQuaQua 2 years 2019-10-29T06:23:32-05:00 0 Answers 270 views 0

Leave an answer

Browse
Browse