How to filter category in ask form

Solved3.05K viewsThemescategory
0

Hi,
This is my category level.

Parent1
 - Child1
 - Child2
 Parent2
 - Child3
 - Child4


I want to only Child3 and Child4 category in ask form.
How can I do it.
Thanks.

Question is closed for new answers.
Answered question
0

Hello,
You can override category field the same way as we do in category addon. Link to line. You can find more detail about our form API here: AnsPress form and validation API.
Cheers!

Selected answer as best
0

Here I have created a sample code for you. You can pass custom arguments for terms query through terms_args

<?php
/**
 * Override AnsPress form category field selection list.
 * 
 * @param mixed $form 
 * @return mixed 
 */
function anspress_override_category_field( $form ){
    $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',
        'terms_args' => array(
            ''
        )
    );
     return $form;
}
add_action( 'ap_question_form_fields', 'anspress_override_category_field', 99999 );

Posted new comment

Wow, Thanks.