prashantcs053
9/12/2017 - 2:11 PM

Add checkbox info from gravity forms to the custom fields of each post

Add checkbox info from gravity forms to the custom fields of each post


add_action("gform_post_submission_2", "set_post_custom_field", 10, 2);
function set_post_custom_field($entry, $form){

$postid = $entry["$post_id"]; //get post id associated with entry 

 $parts = "";
$field_ids = array_keys($entry); //get all field ids of entry
 foreach($field_ids as &$field_id){
	if(substr($field_id,0,2) == 89){    //define $parts as all values from field ids beginning with 89
$parts.= $entry[$field_id] . ',';}
}

$parts = explode(",", $parts);
	//updating custom fields with each value from above into same key
	foreach($parts as &$part){
		if(!empty($part)){
		update_post_meta($postid, 'part_of_plant_used', $part);
		}
		}
}