本文整理汇总了PHP中acf_get_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_get_metadata函数的具体用法?PHP acf_get_metadata怎么用?PHP acf_get_metadata使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_get_metadata函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: acf_get_value
function acf_get_value($post_id, $field)
{
// try cache
$found = false;
$cache = wp_cache_get("load_value/post_id={$post_id}/name={$field['name']}", 'acf', false, $found);
if ($found) {
return $cache;
}
// load value
$value = acf_get_metadata($post_id, $field['name']);
// if value was duplicated, it may now be a serialized string!
$value = maybe_unserialize($value);
// no value? try default_value
if ($value === null && isset($field['default_value'])) {
$value = $field['default_value'];
}
// filter for 3rd party customization
$value = apply_filters("acf/load_value", $value, $post_id, $field);
$value = apply_filters("acf/load_value/type={$field['type']}", $value, $post_id, $field);
$value = apply_filters("acf/load_value/name={$field['name']}", $value, $post_id, $field);
$value = apply_filters("acf/load_value/key={$field['key']}", $value, $post_id, $field);
//update cache
wp_cache_set("load_value/post_id={$post_id}/name={$field['name']}", $value, 'acf');
// return
return $value;
}
示例2: acf_get_field_reference
function acf_get_field_reference($field_name, $post_id)
{
// vars
$field_key = acf_get_metadata($post_id, $field_name, true);
// filter
$field_key = apply_filters('acf/get_field_reference', $field_key, $field_name, $post_id);
// return
return $field_key;
}
示例3: update_value
function update_value($value, $post_id, $field)
{
// remove acfcloneindex
if (isset($value['acfcloneindex'])) {
unset($value['acfcloneindex']);
}
// vars
$order = array();
$layouts = array();
// populate $layouts
foreach ($field['layouts'] as $layout) {
$layouts[$layout['name']] = $layout['sub_fields'];
}
// update sub fields
if (!empty($value)) {
// $i
$i = -1;
// loop through rows
foreach ($value as $row) {
// $i
$i++;
// get layout
$l = $row['acf_fc_layout'];
// append to order
$order[] = $l;
// loop through sub fields
if (!empty($layouts[$l])) {
foreach ($layouts[$l] as $sub_field) {
// value
$v = false;
// key (backend)
if (isset($row[$sub_field['key']])) {
$v = $row[$sub_field['key']];
} elseif (isset($row[$sub_field['name']])) {
$v = $row[$sub_field['name']];
} else {
// input is not set (hidden by conditioanl logic)
continue;
}
// modify name for save
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
// update field
acf_update_value($v, $post_id, $sub_field);
}
// foreach
}
// if
}
// foreach
}
// if
// remove old data
$old_order = acf_get_metadata($post_id, $field['name']);
$old_count = empty($old_order) ? 0 : count($old_order);
$new_count = empty($order) ? 0 : count($order);
if ($old_count > $new_count) {
for ($i = $new_count; $i < $old_count; $i++) {
// get layout
$l = $old_order[$i];
// loop through sub fields
if (!empty($layouts[$l])) {
foreach ($layouts[$l] as $sub_field) {
// modify name for delete
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
// delete value
acf_delete_value($post_id, $sub_field);
}
}
}
}
// save false for empty value
if (empty($order)) {
$order = false;
}
// return
return $order;
}
示例4: acf_get_value
function acf_get_value($post_id = 0, $field)
{
// vars
$cache_key = "get_value/post_id={$post_id}/name={$field['name']}";
// return early if cache is found
if (acf_isset_cache($cache_key)) {
return acf_get_cache($cache_key);
}
// load value
$value = acf_get_metadata($post_id, $field['name']);
// if value was duplicated, it may now be a serialized string!
$value = maybe_unserialize($value);
// no value? try default_value
if ($value === null && isset($field['default_value'])) {
$value = $field['default_value'];
}
// filter for 3rd party customization
$value = apply_filters("acf/load_value", $value, $post_id, $field);
$value = apply_filters("acf/load_value/type={$field['type']}", $value, $post_id, $field);
$value = apply_filters("acf/load_value/name={$field['_name']}", $value, $post_id, $field);
$value = apply_filters("acf/load_value/key={$field['key']}", $value, $post_id, $field);
// update cache
acf_set_cache($cache_key, $value);
// return
return $value;
}
示例5: delete_value
function delete_value($post_id, $key, $field)
{
// get old value (db only)
$old_order = acf_get_metadata($post_id, $field['name']);
// bail early if no rows or no sub fields
if (empty($old_order)) {
return;
}
// vars
$layouts = array();
// populate $layouts
foreach ($field['layouts'] as $layout) {
$layouts[$layout['name']] = $layout['sub_fields'];
}
// loop
foreach ($old_order as $i => $l) {
// bail early if no layout
if (empty($layouts[$l])) {
continue;
}
// loop through sub fields
foreach ($layouts[$l] as $sub_field) {
// modify name for delete
$sub_field['name'] = "{$key}_{$i}_{$sub_field['name']}";
// delete value
acf_delete_value($post_id, $sub_field);
}
}
}
示例6: delete_value
function delete_value($post_id, $key, $field)
{
// get old value (db only)
$old_total = (int) acf_get_metadata($post_id, $field['name']);
// bail early if no rows or no sub fields
if (!$old_total || !$field['sub_fields']) {
return;
}
for ($i = 0; $i < $old_total; $i++) {
foreach ($field['sub_fields'] as $sub_field) {
// modify name for delete
$sub_field['name'] = "{$key}_{$i}_{$sub_field['name']}";
// delete value
acf_delete_value($post_id, $sub_field);
}
// foreach
}
}
示例7: add_row
function add_row($selector, $value, $post_id = false)
{
// filter post_id
$post_id = acf_get_valid_post_id($post_id);
// get field
$field = acf_maybe_get_field($selector, $post_id);
// bail early if no field
if (!$field) {
return false;
}
// get row count
$i = (int) acf_get_metadata($post_id, $field['name']);
// if no rows, save this field via update_field() so that the reference field is created
if (!$i) {
// acf_update_value will return boolean, simply convert this to int for 1 | 0 (the number of rows!)
return (int) acf_update_value(array($value), $post_id, $field);
}
// increase $i
$i++;
// update meta
$result = acf_update_metadata($post_id, $field['name'], $i);
// update sub fields
if ($value) {
foreach ($value as $k => $v) {
update_sub_field(array($field['key'], $i, $k), $v, $post_id);
}
}
// return
return $i;
}
示例8: add_row
function add_row($selector, $value, $post_id = false)
{
// filter post_id
$post_id = acf_get_valid_post_id($post_id);
// get field
$field = acf_maybe_get_field($selector, $post_id);
// bail early if no field
if (!$field) {
return false;
}
// get row count
$i = (int) acf_get_metadata($post_id, $field['name']);
// increase $i
$i++;
// update meta
$result = acf_update_metadata($post_id, $field['name'], $i);
// update sub fields
if ($value) {
foreach ($value as $k => $v) {
update_sub_field(array($field['name'], $i, $k), $v, $post_id);
}
}
// return
return $i;
}