AnsPress_Category::ap_question_form_fields( $form )
Description #
Add category field in ask form.
Parameters #
- $argsarray (Required) Ask form arguments.
Source #
File: addons/free/category.php
public static function ap_question_form_fields( $form ) { if ( wp_count_terms( 'question_category' ) == 0 ) { // WPCS: loose comparison okay. return $form; } $editing_id = ap_sanitize_unslash( 'id', 'r' ); $form['fields']['category'] = array( 'label' => __( 'Category', 'anspress-question-answer' ), 'desc' => __( 'Select a topic that best fits your question.', 'anspress-question-answer' ), 'type' => 'select', 'options' => 'terms', 'order' => 2, 'validate' => 'required,not_zero', ); // Add value when editing post. if ( ! empty( $editing_id ) ) { $categories = get_the_terms( $editing_id, 'question_category' ); if ( $categories ) { $form['fields']['category']['value'] = $categories[0]->term_id; } } return $form; }
Expand full source code Collapse full source code View on GitHub: addons/free/category.php:376
Add your comment