php 将重力形式的复选框信息添加到每个帖子的自定义字段中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 将重力形式的复选框信息添加到每个帖子的自定义字段中相关的知识,希望对你有一定的参考价值。


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);
		}
		}
}

以上是关于php 将重力形式的复选框信息添加到每个帖子的自定义字段中的主要内容,如果未能解决你的问题,请参考以下文章