【发布时间】:2014-09-13 23:55:41
【问题描述】:
我正在开发一个 wp 插件,人们可以在其中加入/取消加入活动。
到目前为止我做了什么:
我制作了一个自定义帖子类型“票证”,其中包含一个动态填充“事件”帖子的帖子标题的 ACF 复选框。在单个事件上,人们可以单击一个按钮,该按钮将创建一个带有 ACF 复选框选中值的票务帖子。如果用户已经有票,它将更新票帖。这一切都很好。
我想要什么:
当用户想取消加入活动时,acf 值必须取消选中。我已经尝试了几件事,比如delete_post_meta($RegisterTicket, 'my_custom_field', $eventname );
部分代码:
在这部分代码之前,我定义了是否必须创建或更新票帖。然后是:
/* Get the current field state */
$field_checked = get_field($field_key, $mypostid);
/* Check if the posttitle already is checked, if so delete_post_meta */
if(is_array($field_checked) && in_array($eventname, $field_checked)) {
delete_post_meta($RegisterTicket, 'my_custom_field', $eventname );
} else {
/* if not already checked, add the title to the array so it will be checked and update_post_meta */
$field_checked[] = $eventname;
update_post_meta($RegisterTicket, 'my_custom_field', $field_checked );
}
update_post_meta($RegisterTicket, 'user', $TheUserID);
delete_post_meta 不起作用,选中的值没有被取消选中。如何解决这个问题?提前致谢。
【问题讨论】:
-
你的If语句是真的吗?
-
是的。我用回声检查了它。
标签: php wordpress checkbox advanced-custom-fields