本文整理汇总了PHP中acf_Field::update_value方法的典型用法代码示例。如果您正苦于以下问题:PHP acf_Field::update_value方法的具体用法?PHP acf_Field::update_value怎么用?PHP acf_Field::update_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类acf_Field
的用法示例。
在下文中一共展示了acf_Field::update_value方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: floatval
function update_value($post_id, $field, $value)
{
// remove ','
$value = str_replace(',', '', $value);
// convert to float. This removes any chars
$value = floatval($value);
// convert back to string. This alows decimals to save
$value = (string) $value;
// update value
parent::update_value($post_id, $field, $value);
}
示例2:
function update_value($post_id, $field, $value)
{
// do stuff with value
// save value
parent::update_value($post_id, $field, $value);
}
示例3: unset
function update_value($post_id, $field, $value)
{
$total = 0;
if ($value) {
// remove dummy field
unset($value[999]);
$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']] : '';
// add to parent value
//$parent_value[$i][$sub_field['name']] = $v;
// 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);
}
}
}
parent::update_value($post_id, $field, $total);
}
示例4: 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 => $value) {
$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, $value);
}
}
}
parent::update_value($post_id, $field, $total);
}
示例5: strtotime
function update_value($post_id, $field, $value)
{
$field = array_merge($this->defaults, $field);
if ($value != '' && $field['save_as_timestamp'] == 'true') {
if (preg_match('/^dd?\\//', $field['date_format'])) {
//if start with dd/ or d/ (not supported by strtotime())
$value = str_replace('/', '-', $value);
}
$value = strtotime($value);
}
parent::update_value($post_id, $field, $value);
}
示例6: 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);
}
示例7: update_value
/**
* (non-PHPdoc)
* @see acf_Field::update_value()
*/
public function update_value($post_id, $field, $value)
{
$this->set_field_defaults($field);
if ($field['set_post_terms']) {
$terms = array();
foreach ((array) $value as $item) {
if (intval($item) > 0) {
$terms[] = intval($item);
} else {
$terms[] = strval($item);
}
}
$value = wp_set_object_terms($post_id, $terms, $field['taxonomy'], false);
}
parent::update_value($post_id, $field, $value);
}
示例8: isset
/**
* Process the post edit submit
*
* Convert the various fields into a single value (minutes since the start of the day) to save to the database.
*/
function update_value($post_id, $field, $value)
{
$field['24_hour'] = isset($field['24_hour']) ? $field['24_hour'] : false;
// do stuff with value
// Convert the parts into minutes since the start of the day
if ($field['24_hour']) {
$val = $value['hour'] * 60 + $value['minute'];
} else {
$val = $value['hour'] % 12 * 60 + $value['minute'];
if ($value['meridiem'] == 'pm') {
$val += 12 * 30;
}
}
// save value
parent::update_value($post_id, $field, $val);
}
示例9: 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);
}
示例10: update_value
/**
* (non-PHPdoc)
* @see acf_Field::update_value()
*/
public function update_value($post_id, $field, $value)
{
$this->set_field_defaults($field);
if (in_array($field[self::FIELD_SET_TERMS], array(self::SET_TERMS_APPEND, self::SET_TERMS_OVERRIDE))) {
$terms = array();
foreach ((array) $value as $item) {
if (intval($item) > 0) {
$terms[] = intval($item);
} else {
$terms[] = strval($item);
}
}
wp_set_object_terms($post_id, $terms, $field[self::FIELD_TAXONOMY], $field[self::FIELD_SET_TERMS] == self::SET_TERMS_APPEND);
}
parent::update_value($post_id, $field, $value);
}
示例11: update_value
/**
* (non-PHPdoc)
* @see acf_Field::update_value()
*/
public function update_value($post_id, $field, $value)
{
$field = array_merge($this->defaults, $field);
foreach ($value as $key => $item) {
$items = explode(',', $item);
foreach ($items as $item) {
if (is_numeric($item)) {
$values[$key]['ngg_id'] = intval($item);
} else {
$values[$key]['ngg_form'] = strval($item);
}
}
}
parent::update_value($post_id, $field, $values);
}
示例12: floatval
function update_value($post_id, $field, $value)
{
// making sure value is a number / converting number with two decimal places at all times.
$value['price'] = floatval($value['price']);
$value['price'] = number_format($value['price'], 2, '.', '');
// save value
parent::update_value($post_id, $field, $value);
}