Hi Souhir,
Thank you for the patience, this is actually going to take some custom work to do but it is still possible.
What you are going to have to do is to rewrite your taxonomy in the form as a cred generic field. Take a look at my example below.
[cred_generic_field type='select' field='parent_category']
{
"required":0,
"default":[],
"options":[{"value":"35","label":"Business"},{"value":"41","label":"Featured"},{"value":"29","label":"World"}]
}
[/cred_generic_field]
Notice that I created a custom select field using the Cred Generic field option and re-added my taxonomy to it. So for the Labels i use the taxonomy name and for the value I use the taxonomy ID. Now since you want the ID you can get it by going to the taxonomy edit page and clicking on the term you want the ID for and in the URL you should see the Tag_ID parameter.
Now I named my field parent_category for simplicity.
Next we need to separate the child terms. So for each parent category you will need to create a separate generic list for the child. Example.
[cred_show_group if="( $(parent_category) eq '35' )" mode="fade-slide"]
[cred_generic_field type='select' field='child_category2']
{
"required":0,
"default":[],
"options":[{"value":"37","label":"Finance"},{"value":"36","label":"Management"}]
}
[/cred_generic_field]
[/cred_show_group]
[cred_show_group if="( $(parent_category) eq '29' )" mode="fade-slide"]
[cred_generic_field type='select' field='child_category2']
{
"required":0,
"default":[],
"options":[{"value":"37","label":"Finance"},{"value":"36","label":"Management"}]
}
[/cred_generic_field][/cred_show_group]
If you also notice that around each field group you will see that i've added the conditional for the groups so they only show based on what parent was selected.
Now to make all this work you will need the code below.
add_action('cred_save_data', 'cust_set_cat',10,2);
function cust_set_cat($post_id, $form_data){
if ($form_data['id']==602){
if($_POST['parent_category']==35){
wp_set_post_terms( $post_id, $_POST['parent_category'], 'category' );
if(isset($_POST['child_category1'])){
wp_set_post_terms( $post_id, $_POST['child_category1'], 'category', true );
}
}
if($_POST['parent_category']==29){
wp_set_post_terms( $post_id, $_POST['parent_category'], 'category' );
if(isset($_POST['child_category2'])){
wp_set_post_terms( $post_id, $_POST['child_category2'], 'category', true );
}
}
}
}
You will notice that I have set my first condition to 602 and this is because I only want it to work for only the Form with ID 602. The other if statements correspond to their respective terms.
It should be noted that you will need an if statement for each parent category and child category.
Please let me know if this example was clear.
Thanks,
Shane