本文整理匯總了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);
}