Title: Question form custom fields not working
Last modified: August 1, 2022

---

# Question form custom fields not working

 *  [modeman](https://wordpress.org/support/users/modeman/)
 * (@modeman)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/question-form-custom-fields-not-working/)
 * Hello, we have updated wordpress and anspress plugin, after that our custom code
   who adds and safes custom fields not working. Do not saves fields. Can you please
   check whats wrong?
 * Code:
 *     ```
       /**
        * Adds a PDF field to AnsPress question form.
        *
        * @param array $form Form arguments.
        * @return void
        */
       function my_custom_question_field( $form ) {
   
        // field.
         $form['fields']['date'] = array(
           'label'   => __( 'Jūsų ar žmogaus, dėl kurio klausiate gimimo data ir laikas:' ),
           'desc'    => __( 'Tiksli data svarbi sudarant atsakymą.' ),
           'subtype' => 'text', // Default type is set to input.
           'attr'    => array(
             'placeholder' => 'Pvz.: 1991-08-25 14h 20min',
           ),
         'sanitize'      => 'text_field', // This sanitize will be applied by default for url field.
         'validate'      => 'required,max_string_length', // Require and check length of string.
         );
   
       	 $form['fields']['city'] = array(
           'label'   => __( 'Gimimo miestas' ),
           'desc'    => __( '' ),
           'subtype' => 'text', // Default type is set to input.
           'attr'    => array(
             'placeholder' => 'Pvz.: Vilnius',
           ),
         'sanitize'      => 'text_field', // This sanitize will be applied by default for url field.
         'validate'      => 'required,max_string_length', // Require and check length of string.
         );	
   
         return $form;
       }
       add_filter( 'ap_question_form_fields', 'my_custom_question_field' );
   
       /**
        * Save a upload field.
        */
       function my_save_pdf_uploads($post_id,$post) {
        $form = anspress()->get_form( 'form_question' );
       	// Get all sanitized values.
       	$values = $form->get_values();
         if ( ! add_post_meta( $post_id, 'user_date', $values['date']['value'], true ) ) {
       update_post_meta( $post_id, 'user_date', $values['date']['value'] );
       }
        if ( ! add_post_meta( $post_id, 'user_city', $values['city']['value'], true ) ) {
       update_post_meta( $post_id, 'user_city', $values['city']['value'] );
       }
   
       }
       add_action( 'ap_processed_new_question', 'my_save_pdf_uploads' );
       ```
   

The topic ‘Question form custom fields not working’ is closed to new replies.

 * ![](https://ps.w.org/anspress-question-answer/assets/icon-256x256.png?rev=2432843)
 * [AnsPress - Question and answer](https://wordpress.org/plugins/anspress-question-answer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/anspress-question-answer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/anspress-question-answer/)
 * [Active Topics](https://wordpress.org/support/plugin/anspress-question-answer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/anspress-question-answer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/anspress-question-answer/reviews/)

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * 0 replies
 * 1 participant
 * Last reply from: [modeman](https://wordpress.org/support/users/modeman/)
 * Last activity: [3 years, 9 months ago](https://wordpress.org/support/topic/question-form-custom-fields-not-working/)
 * Status: not resolved