Hi Laurie,
I've looked at this again for you.
I was able to get the taxonomy to be set with a modification of this code here.
add_action('cred_save_data', 'set_company_name',10,2);
function set_company_name($post_id, $form_data)
{
// if a specific form
if ($form_data['id']=4305)
{
$title = get_the_title($post_id);
update_post_meta($post_id, 'wpcf-company_title',$title);
if (isset($_POST['gen-biz-category'])){
wp_set_post_terms($post_id,$_POST['gen-biz-category'],'business-category');
if(isset($_POST['animal-care'])){
wp_set_post_terms($post_id,$_POST['animal-care'],'business-category',true);
}
}
}
}
As you can see this is the original code that I gave you with some modifications.
The actual modification is this.
if (isset($_POST['gen-biz-category'])){
wp_set_post_terms($post_id,$_POST['gen-biz-category'],'business-category');
if(isset($_POST['animal-care'])){
wp_set_post_terms($post_id,$_POST['animal-care'],'business-category',true);
}
}
Where i'm checking if the customer selects the taxonomy and if they did, i update the post with the correct terms.
Now what you need to do is to add the condition for each child section. As you can see i've added the code to check if the user select Animal Care and then set the child selection for animal care.
To add a the checks for the other terms you will need to add an if statement. Here is an example if the user selected Arts Literature.
if (isset($_POST['gen-biz-category'])){
wp_set_post_terms($post_id,$_POST['gen-biz-category'],'business-category');
if(isset($_POST['animal-care'])){
wp_set_post_terms($post_id,$_POST['animal-care'],'business-category',true);
}
if(isset($_POST['arts-literature'])){
wp_set_post_terms($post_id,$_POST['arts-literature'],'business-category',true);
}
}
Notice all I did was to just add a new if statement within the gen-biz-category if statement as this is a nested code.
Now finally the most important thing is that when we are using the wp_set_post_terms() function we are required to use the term ID rather than the slug. What you have on the form is the term slug as your value. See Screenshot
If you Notice for the Animal Care option I replaced the slug with the Term ID. The term ID can be found by editing the taxonomy term and look for the tag_ID parameter in the URL.
This is going to take some changes but should work perfectly fine after you've added the necessary code and made changes to your value attribute.
Please let me know if this helps.
Thanks,
Shane