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


PHP acf_delete_value函数代码示例

本文整理汇总了PHP中acf_delete_value函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_delete_value函数的具体用法?PHP acf_delete_value怎么用?PHP acf_delete_value使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了acf_delete_value函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: update_value

 function update_value($value, $post_id, $field)
 {
     // remove acfcloneindex
     if (isset($value['acfcloneindex'])) {
         unset($value['acfcloneindex']);
     }
     // vars
     $total = 0;
     // update sub fields
     if (!empty($value)) {
         // $i
         $i = -1;
         // loop through rows
         foreach ($value as $row) {
             // $i
             $i++;
             // increase total
             $total++;
             // loop through sub fields
             if (!empty($field['sub_fields'])) {
                 foreach ($field['sub_fields'] 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 value
                     acf_update_value($v, $post_id, $sub_field);
                 }
                 // foreach
             }
             // if
         }
         // foreach
     }
     // if
     // get old value (db only)
     $old_total = intval(acf_get_value($post_id, $field, true));
     if ($old_total > $total) {
         for ($i = $total; $i < $old_total; $i++) {
             foreach ($field['sub_fields'] 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);
             }
             // foreach
         }
         // for
     }
     // if
     // update $value and return to allow for the normal save function to run
     $value = $total;
     // return
     return $value;
 }
开发者ID:quangnpd,项目名称:jobshop_web,代码行数:64,代码来源:repeater.php

示例3: delete_field

function delete_field($selector, $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);
    // delete
    return acf_delete_value($post_id, $field);
}
开发者ID:de190909,项目名称:WPTest,代码行数:9,代码来源:api-template.php

示例4: 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

示例5: delete_field

function delete_field($selector, $post_id = false)
{
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // get field
    $field = get_field_object($selector, $post_id, false, false);
    // delete
    return acf_delete_value($post_id, $field['name']);
}
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:9,代码来源:api-template.php

示例6: delete_value

 function delete_value($post_id, $key, $field)
 {
     // get old value (db only)
     $old_total = intval(acf_get_value($post_id, $field, true));
     // 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:slavic18,项目名称:cats,代码行数:18,代码来源:repeater.php


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