I am having trouble populating a checklist with the checked values of a post, and then update the terms after submission. The post being edited is sent to the form by query string, and I did fine getting the name and values for the taxonomy in the form. However, everything I have tried for checking boxes and the setting post terms hasn't worked, wondering if anyone knows what I am doing wrong?
Here is the pre-render with just the taxonomy and values, I tried using, wp_get_post_terms and differnt ways to get the checked values in, but couldn't
add_filter('gform_pre_render_2', 'populate_each_product');
function populate_each_product ($form){
global $post, $wpdb;
$id = $_GET['kr_id'];
if(!empty($id)){
foreach($form["fields"] as &$field){
if($field["id"] == 3){
$args = array( 'hide_empty' => false, );
$cats = get_terms('product_category', $args);
$field['choices'] = array();
foreach ($cats as $cat){
$name = $cat -> name;
$val = $cat -> term_id;
$field['choices'][] = array( 'text' => $name,'value' => $val);
}
}
}
return $form;
}
}
As far as post submission I have tried tons of different ways to get it to set_post_Terms but couldn't get anything to work
add_filter('gform_post_submission_2', 'GF_update_product');
function GF_update_product ($entry) {
global $wpdb, $post;
$id= $_GET['kr_id'];
$entry["3"] = array();
foreach($entry["3"]->value as $term){
wp_set_post_terms($id, $term, 'product_category' );
}
}