Categories::ap_question_form_fields( array $form )
Description #
Add category field in ask form.
Parameters #
- $formarray (Required) Ask form arguments.
Source #
File: addons/categories/categories.php
public function ap_question_form_fields( $form ) {
if ( wp_count_terms( 'question_category' ) == 0 ) { // phpcs:ignore
return $form;
}
$editing_id = ap_sanitize_unslash( 'id', 'r' );
$category_id = ap_sanitize_unslash( 'category', '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;
}
} elseif ( ! empty( $category_id ) ) {
$form['fields']['category']['value'] = (int) $category_id;
}
return $form;
}
Expand full source code Collapse full source code View on GitHub: addons/categories/categories.php:426
Add your comment