Tell us what you are trying to do? I have a form which now has some required fields, such as name, state and county. I have a taxonomy called StatesCounties which is hierarchical, with a State and under it all of its Counties. But filling out the form does not set the taxonomy, or i thought it used to but not now. How to make sure if someone fills out this form, those taxonomies get included in its data?
Is there any documentation that you are following? no
Is there a similar example that we can see? you can fill out the form at
hidden link , and then i could take a screen shot showing me edit the item
and show that the StatesCounties categories are empty for its data.
These terms are needed for mapping the user who filled out the form, on the website map by state and county.
What is the link to your site? hidden link
Hello,
I assume we are talking about those two fields of the URL you mentioned above:
- State
- County
They seem to be custom fields, if you want to use the custom field values to setup the taxonomy "StatesCounties " value, it needs custom codes, for example:
1) When user submit the form, use action hook "cred_save_data" to trigger a PHP function:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
2) In this PHP function, get the those custom field values:
- State
- County
https://developer.wordpress.org/reference/functions/get_post_meta/
Then use above values to update the taxonomy "StatesCounties " value:
https://developer.wordpress.org/reference/functions/wp_set_object_terms/
just to be sure we are on the same page before i attempt anything, see these snapshots
please let me know if your answers are still relevant to my situation.
thanks!
i found some code that i am working with to try to write to the StatesCounties taxonomy for the user who filled out the CRED form.
At the toolset dashboard when i edit the form i am using the part of the url for the form id ( see attached) is this the correct id?
add_action('cred_save_data', 'category_save_data_action',20,2);
function category_save_data_action($post_id, $form_data){
// if a specific form
if ($form_data['id']==699) {
$parent_post_id = $_GET['parent_assignment_id'];
$parent_terms = wp_get_object_terms( $parent_post_id, 'lab-categories', array('ids') );
if(!empty($parent_terms)) {
$parent_term_ids = array();
foreach($parent_terms as $parent_term) {
if($parent_term->term_id != '') {
$parent_term_ids[] = $parent_term->term_id;
}
}
if(count($parent_term_ids) > 0) {
wp_set_object_terms( $post_id, $parent_term_ids , 'lab-categories' );
}
}
}
}
My issue is resolved now. Thank you!