Skip to content

Instantly share code, notes, and snippets.

@rahularyan
Created October 24, 2017 01:45
Show Gist options
  • Save rahularyan/4c89eac75f51738f06c1fa88ac7dbd49 to your computer and use it in GitHub Desktop.
Save rahularyan/4c89eac75f51738f06c1fa88ac7dbd49 to your computer and use it in GitHub Desktop.
Add custom fields to AnsPress ask form.
<?php
/**
* 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 ) {
// Url field.
$form['fields']['website'] = array(
'label' => __( 'Your website' ),
'desc' => __( 'Enter link to your website.' ),
'subtype' => 'url', // Default type is set to input.
'attr' => array(
'placeholder' => 'https://mydomain.com/',
),
);
// Upload field.
$form['fields']['screenshot'] = array(
'label' => __( 'Screenshot' ),
'desc' => __( 'Upload screenshots of your website.' ),
'type' => 'upload',
'upload_args' => array(
'multiple' => false, // Only allow single image upload.
),
);
return $form;
}
add_filter( 'ap_question_form_fields', 'my_custom_question_field' );
@Amoosimeon
Copy link

Hello, this works perfectly but contents of the custom field are not getting saved in the question upon submitting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment