我没有正确保存此内容。 如何保存自定义字段?
▼Cretae新的自定义字段:
function custom_form_fields( $form ) {
$form['fields']['check'] = array(
'type' => 'checkbox',
'options' => array(
'check-1' => 'check1',
'check-2' => 'check2'
),
);
return $form;
}
add_filter( 'ap_question_form_fields', 'my_custom_question_field' );
▼保存字段:
function question_mysave( $post_id, $post ) {
global $validate;
if ( empty( $validate ) ) {
return;
}
$fields = $validate->get_sanitized_fields();
update_post_meta( $post_id, 'check', $fields['check'] );
}
add_action( 'ap_processed_new_question', array( $this, 'question_mysave' ), 0, 2 );
add_action( 'ap_processed_update_question', array( $this, 'question_mysave' ), 0, 2 );
不保存自定义字段。 ¿为什么?
样本:https://anspress.io/resources/faq/anspress-form-and-validation-api/
答案 0 :(得分:0)
您需要删除
global $validate;
if ( empty( $validate ) ) {
return;
}
并使用它来获取表单的值:
$form = anspress()->get_form( 'question_form' );
// Get all sanitized values.
$values = $form->get_values();
update_post_meta( $post_id, 'check', $fields['check']['value'] );