So I have a custom post type called "Lesson Plans" (i.e. "lessonplans")
Within that I have a taxonomy called "Classes / Teachers" (i.e. "class")
The taxonomies are the teacher's display names: Jane Smith, John Doe, etc., etc.
I have a field that auto-populates to fill in the teacher's name based on the user who is using the form (i.e. Jane or John etc.)
How do I get that field to post into the corresponding taxonomy?
Here is the code I have so far...
add_action('gform_post_submission', 'gform_add_lessonplans', 10, 2);
function gform_add_lessonplans($entry, $form){
if(!rgar($entry, 'post_id'))
return;
$post_id = rgar($entry, 'post_id');
$valid_cat_ids = get_term_ids();
$cat_ids = array();
foreach($form['fields'] as $field){
if(strpos($field['cssClass'], 'add_lessonplans') === false)
continue;
foreach($entry as $key => $value){
if(intval($key) != $field['id'] || !in_array($value, $valid_cat_ids))
continue;
$cat_ids[] = (int) $value;
}
}
wp_set_object_terms($post_id, $cat_ids, 'class', false);
}
function get_term_ids(){
$categories = get_terms('class', 'hide_empty=0');
$cat_ids = array();
foreach($categories as $category)
$cat_ids[] = $category->term_id;
return $cat_ids;
}
function print_rr($array){
echo '<pre>';
print_r($array);
echo '</pre>';
}
Thanks!