Custom Fields made, where is my data stored? and how to retrieve it?

2.89K viewsCore
1

hello, i made 2 custom fields and added it to the ask form using the following:

/**
 * Add custom fields to AnsPress question form.
 * 
 * This hook will add two new fields in ask form.
 *
 * @param array $form Form arguments.
 * @return void
 */
function my_custom_question_field( $form ) {
 // City Field
 $form['fields']['City'] = array(
   'label'   => __( 'City' ),
   'desc'    => __( 'Enter name of your city.' ),
   'subtype' => 'text', // Default type is set to input.
   'attr'    => array(
  'placeholder' => 'Example: Jaipur, Pune, etc.',
   ),
 );
    // City Field
 $form['fields']['Ph.Number'] = array(
  'label'   => __( 'Phone Number' ),
  'desc'    => __( 'Enter Your mobile/Whatsapp number' ),
  'subtype' => 'tel', // Default type is set to input.
  'attr'    => array(
    'placeholder' => 'Phone Number',
  ),
   );
 return $form;
  }
     add_filter( 'ap_question_form_fields', 'my_custom_question_field' );

now, i want to know where this data is stored, and how can i show this to the backend for my client, cheers!

Answered question
0

hello, so adding the code snippet from github is okay, can you please share one line of code to save a text field and update it in post meta?
thanks,
Naman

Answered question
0

Hello,
AnsPress does not save custom fields automatically. You need to use init hook. Here is an example
https://gist.github.com/rahularyan/ea30cb2c455c4e9a442fefcf2d969014#file-save-custom-form-php
More details can be found here: https://anspress.net/resources/faq/anspress-form-and-validation-api/

Answered question