当前位置: 首页>>代码示例>>PHP>>正文


PHP acf_get_metadata函数代码示例

本文整理汇总了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;
}
开发者ID:johannes-klaushofer,项目名称:modolab,代码行数:26,代码来源:api-value.php

示例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;
}
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:9,代码来源:api-template.php

示例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;
 }
开发者ID:Aqro,项目名称:NewDWM,代码行数:77,代码来源:flexible-content.php

示例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;
}
开发者ID:Garth619,项目名称:Femi9,代码行数:26,代码来源:api-value.php

示例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);
         }
     }
 }
开发者ID:cimocimocimo,项目名称:staydrysystems.com,代码行数:29,代码来源:flexible-content.php

示例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
     }
 }
开发者ID:Aqro,项目名称:NewDWM,代码行数:18,代码来源:repeater.php

示例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;
}
开发者ID:gecugamo,项目名称:customledgers,代码行数:30,代码来源:api-template.php

示例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;
}
开发者ID:johannes-klaushofer,项目名称:modolab,代码行数:25,代码来源:api-template.php


注:本文中的acf_get_metadata函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。