I am trying to assign the values chosen by the user from a dropdown list of custom field values to a custom taxonomy.

It works perfectly if the taxonomy is not hierarchical, but I have no idea how to do it when I have to assign the field value as a child term.


The taxonomy is called "location".

The parent terms are the provinces of Belgium, the first-level children are the comunes and the second-level children are the villages/towns.

In the front-end, I am using Toolset CRED forms to collect data about users, so they select the province / commune / town from dropdown lists that display by using custom logic (if Liege is selected, then list only Liege comunes and so on). So the custom fields logic is not a problem. I know how to use wp_set_object_terms to transfer the value of the field to a taxonomy terms, e.g.:

if ($form_data['id']==100)
        if (isset($_POST['wpcf-province']))
                wp_set_object_terms($post_id, $_POST['wpcf-province'], 'location',false);

In the above code (that works perfectly), $post_id is the ID of the post being created / edited (with the form having the ID 100), wpcf-province is the custom field that retains the province name and false means that I do not want to apend it, but to replace it, if it exists (the same code is used for editing). The question is not Toolset related, but WordPress related (I only use Toolset for the power of its Views and the ease to create / edit custom post types and custom fields).

My question is the following: The code works very well but... only for the parent term. I have no idea how I can take the value from the field wpcf-commune and assign it as a child term of the aforementioned taxonomy term. Please help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.