本文整理汇总了PHP中acf_Field::delete_value方法的典型用法代码示例。如果您正苦于以下问题:PHP acf_Field::delete_value方法的具体用法?PHP acf_Field::delete_value怎么用?PHP acf_Field::delete_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类acf_Field
的用法示例。
在下文中一共展示了acf_Field::delete_value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function update_value($post_id, $field, $value)
{
$sub_fields = array();
foreach ($field['layouts'] as $layout) {
foreach ($layout['sub_fields'] as $sub_field) {
$sub_fields[$sub_field['key']] = $sub_field;
}
}
$total = array();
if ($value) {
// remove dummy field
unset($value['acfcloneindex']);
$i = -1;
// loop through rows
foreach ($value as $row) {
$i++;
// increase total
$total[] = $row['acf_fc_layout'];
unset($row['acf_fc_layout']);
// loop through sub fields
foreach ($row as $field_key => $v) {
$sub_field = $sub_fields[$field_key];
// update full name
$sub_field['name'] = $field['name'] . '_' . $i . '_' . $sub_field['name'];
// save sub field value
$this->parent->update_value($post_id, $sub_field, $v);
}
}
}
/*
* Remove Old Data
*
* @credit: http://support.advancedcustomfields.com/discussion/1994/deleting-single-repeater-fields-does-not-remove-entry-from-database
*/
$old_total = parent::get_value($post_id, $field);
$old_total = count($old_total);
$new_total = count($total);
if ($old_total > $new_total) {
foreach ($sub_fields as $sub_field) {
for ($j = $new_total; $j < $old_total; $j++) {
parent::delete_value($post_id, $field['name'] . '_' . $j . '_' . $sub_field['name']);
}
}
}
parent::update_value($post_id, $field, $total);
}
示例2: unset
function update_value($post_id, $field, $value)
{
$total = 0;
if ($value) {
// remove dummy field
unset($value['acfcloneindex']);
$i = -1;
// loop through rows
foreach ($value as $row) {
$i++;
// increase total
$total++;
// loop through sub fields
foreach ($field['sub_fields'] as $sub_field) {
// get sub field data
$v = isset($row[$sub_field['key']]) ? $row[$sub_field['key']] : '';
// update full name
$sub_field['name'] = $field['name'] . '_' . $i . '_' . $sub_field['name'];
// save sub field value
$this->parent->update_value($post_id, $sub_field, $v);
}
}
}
/*
* Remove Old Data
*
* @credit: http://support.advancedcustomfields.com/discussion/1994/deleting-single-repeater-fields-does-not-remove-entry-from-database
*/
$old_total = (int) parent::get_value($post_id, $field);
if ($old_total > $total) {
foreach ($field['sub_fields'] as $sub_field) {
for ($j = $total; $j < $old_total; $j++) {
parent::delete_value($post_id, $field['name'] . '_' . $j . '_' . $sub_field['name']);
}
}
}
// update repeater count
parent::update_value($post_id, $field, $total);
}