我尝试通过post创建(wp\\u insert\\u post)将数组存储在多个自定义字段中。数组是$event\\u test,键是meta\\u输入上的event\\u test。
表单提交时,将显示自定义字段,但其为空。
// 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);