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


PHP acf_update_value函数代码示例

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


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

示例1: update_item

 public function update_item($request)
 {
     $item = $this->prepare_item_for_database($request);
     if (is_array($item) && count($item) > 0) {
         foreach ($item['data'] as $key => $value) {
             if (isset($item['fields'][$key]['key'])) {
                 $field = $item['fields'][$key];
                 $type = $field['type'];
                 if ($type == "true_false") {
                     switch ($value) {
                         case "true":
                             $value = 1;
                             break;
                         case "false":
                             $value = 0;
                             break;
                     }
                 }
                 if (function_exists('acf_update_value')) {
                     acf_update_value($value, $item['id'], $field);
                 } elseif (function_exists('update_field')) {
                     update_field($field['key'], $value, $item['id']);
                 } else {
                     do_action('acf/update_value', $value, $item['id'], $field);
                 }
             }
         }
         return new WP_REST_Response($this->get_fields($request), 200);
     }
     return new WP_Error('cant_update_item', __("Cannot update item", 'acf-to-rest-api'), array('status' => 500));
 }
开发者ID:der-lukas,项目名称:acf-to-rest-api,代码行数:31,代码来源:class-acf-to-rest-api-controller.php

示例2: save_post

 function save_post($post_id = 0)
 {
     // save $_POST data
     foreach ($_POST['acf'] as $k => $v) {
         // get field
         $field = acf_get_field($k);
         // update field
         if ($field) {
             acf_update_value($v, $post_id, $field);
         }
     }
 }
开发者ID:TMBR,项目名称:johnjohn,代码行数:12,代码来源:input.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: 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

示例5: updateUserStatus

function updateUserStatus($statusId)
{
    acf_update_value();
}
开发者ID:AllFamous,项目名称:camella,代码行数:4,代码来源:functions.php

示例6: psp_update_sub_field

function psp_update_sub_field($selector, $value, $post_id = false)
{
    // filter post_id
    // $post_id = acf_get_valid_post_id( $post_id );
    // vars
    $field = false;
    $name = '';
    // within a have_rows loop
    if (is_string($selector)) {
        // loop over global data
        if (!empty($GLOBALS['acf_field'])) {
            foreach ($GLOBALS['acf_field'] as $row) {
                // add to name
                $name .= "{$row['name']}_{$row['i']}_";
                // override $post_id
                $post_id = $row['post_id'];
            }
        }
        // get sub field
        $field = get_sub_field_object($selector);
        // create dummy field
        if (!$field) {
            $field = acf_get_valid_field(array('name' => $selector, 'key' => '', 'type' => ''));
        }
        // append name
        $name .= $field['name'];
        // update name
        $field['name'] = $name;
    } elseif (is_array($selector)) {
        // validate
        if (count($selector) < 3) {
            return false;
        }
        // vars
        $parent_name = acf_extract_var($selector, 0);
        // load parent
        $field = get_field_object($parent_name, $post_id, false, false);
        // add to name
        $name .= "{$field['name']}";
        // sub fields
        foreach ($selector as $s) {
            if (is_numeric($s)) {
                $row_i = intval($s) - 1;
                // add to name
                $name .= "_{$row_i}";
            } else {
                // update parent
                $field = acf_get_sub_field($s, $field);
                // create dummy field
                if (!$field) {
                    $field = acf_get_valid_field(array('name' => $s, 'key' => '', 'type' => ''));
                }
                // add to name
                $name .= "_{$field['name']}";
            }
            // if
        }
        // foreach
        // update name
        $field['name'] = $name;
    }
    // save
    return acf_update_value($value, $post_id, $field);
}
开发者ID:VLabsInc,项目名称:WordPressPlatforms,代码行数:64,代码来源:transition.php

示例7: update_value

 function update_value($value, $post_id, $field)
 {
     // bail early if no value
     if (!acf_is_array($value) || !acf_is_array($field['sub_fields'])) {
         return null;
     }
     // modify
     $field = $this->prepare_field_for_save($field);
     // loop
     foreach (array_keys($field['sub_fields']) as $i) {
         // vars
         $sub_field = $field['sub_fields'][$i];
         $v = false;
         // key (backend)
         if (isset($value[$sub_field['key']])) {
             $v = $value[$sub_field['key']];
             // name (frontend)
         } elseif (isset($value[$sub_field['_name']])) {
             $v = $value[$sub_field['_name']];
             // empty
         } else {
             // input is not set (hidden by conditioanl logic)
             continue;
         }
         // update value
         acf_update_value($v, $post_id, $sub_field);
     }
     // return
     return '';
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:30,代码来源:clone.php

示例8: update_sub_field

function update_sub_field($selector, $value, $post_id = false)
{
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // vars
    $field = false;
    // within a have_rows loop
    if (is_string($selector)) {
        // get current row
        $row = acf_get_row();
        // override $post_id
        $post_id = $row['post_id'];
        // get sub field
        $field = get_sub_field_object($selector, false, false);
        // create dummy field
        if (!$field) {
            $field = acf_get_valid_field(array('name' => $selector, 'key' => '', 'type' => ''));
        }
        // update name
        $field['name'] = "{$row['name']}_{$row['i']}_{$field['name']}";
    } elseif (is_array($selector)) {
        // validate
        if (count($selector) < 3) {
            return false;
        }
        // vars
        $parent_name = acf_extract_var($selector, 0);
        // load parent
        $field = acf_maybe_get_field($parent_name, $post_id);
        // add to name
        $name = "{$field['name']}";
        // sub fields
        foreach ($selector as $s) {
            if (is_numeric($s)) {
                $row_i = intval($s) - 1;
                // add to name
                $name .= "_{$row_i}";
            } else {
                // update parent
                $field = acf_get_sub_field($s, $field);
                // create dummy field
                if (!$field) {
                    $field = acf_get_valid_field(array('name' => $s, 'key' => '', 'type' => ''));
                }
                // add to name
                $name .= "_{$field['name']}";
            }
            // if
        }
        // foreach
        // update name
        $field['name'] = $name;
    }
    // delete
    if ($value === null) {
        return acf_delete_value($post_id, $field);
    }
    // update
    return acf_update_value($value, $post_id, $field);
}
开发者ID:de190909,项目名称:WPTest,代码行数:60,代码来源:api-template.php

示例9: save_post

 function save_post($post_id)
 {
     // bail early if empty
     if (empty($_POST['acf'])) {
         return;
     }
     // save $_POST data
     foreach ($_POST['acf'] as $k => $v) {
         // get field
         $field = acf_get_field($k);
         // continue if no field
         if (!$field) {
             continue;
         }
         // update
         acf_update_value($v, $post_id, $field);
     }
 }
开发者ID:ashenkar,项目名称:sanga,代码行数:18,代码来源:input.php

示例10: update_value

 function update_value($value, $post_id, $field)
 {
     if (!empty($value)) {
         foreach ($value as $field_key => $field_value) {
             foreach ($field['sub_fields'] as $sub_field) {
                 if ($field_key == $sub_field['key']) {
                     // update field
                     $sub_field_name = $sub_field['name'];
                     $sub_field['name'] = "{$field['name']}_{$sub_field_name}";
                     acf_update_value($field_value, $post_id, $sub_field);
                     break;
                 }
             }
         }
     }
     return null;
 }
开发者ID:devgeniem,项目名称:acf-reusable-field-group,代码行数:17,代码来源:acf-reusable_field_group-v5.php

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

示例12: acf_save_post

function acf_save_post($post_id = 0)
{
    // loop through and save
    if (!empty($_POST['acf'])) {
        // loop through and save $_POST data
        foreach ($_POST['acf'] as $key => $value) {
            // get field
            $field = acf_get_field($key);
            // validate field
            if (!$field) {
                continue;
            }
            // update field
            acf_update_value($value, $post_id, $field);
        }
        // foreach($fields as $key => $value)
    }
    // if($fields)
    // hook for 3rd party customization
    do_action('acf/save_post', $post_id);
    return $post_id;
}
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:22,代码来源:input.php

示例13: delete_sub_row

function delete_sub_row($selector, $i = 1, $post_id = false)
{
    // vars
    $sub_field = false;
    $i--;
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // get sub field
    if (is_array($selector)) {
        $sub_field = acf_maybe_get_sub_field($selector, $post_id, false);
    } else {
        $sub_field = get_row_sub_field($selector);
    }
    // bail early if no sub field
    if (!$sub_field) {
        return false;
    }
    // get raw value
    $value = acf_get_value($post_id, $sub_field);
    // ensure array
    $value = acf_get_array($value);
    // append
    unset($value[$i]);
    // update
    return acf_update_value($value, $post_id, $sub_field);
}
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:26,代码来源:api-template.php

示例14: update_acf_fields

 protected function update_acf_fields()
 {
     if (!$this->post_id) {
         return;
     }
     foreach ($this->acf_fields as $data) {
         if (!isset($data['value'])) {
             continue;
         }
         $field = $data['field'];
         $value = $data['value'];
         if (function_exists('acf_update_value')) {
             acf_update_value($value, $this->post_id, $field);
         } elseif (function_exists('update_field')) {
             update_field($field['key'], $value, $this->post_id);
         } else {
             do_action('acf/update_value', $value, $this->post_id, $field);
         }
     }
 }
开发者ID:solutionworks,项目名称:theme-setup,代码行数:20,代码来源:Migration.php

示例15: update_value

 public function update_value($value, $post_id, $field)
 {
     global $wp_widget_factory;
     $widget = isset($field['value']) && isset($field['value']['the_widget']) ? $field['value']['the_widget'] : $field['widget'];
     // This is a chance for plugins to replace missing widgets
     $the_widget = !empty($wp_widget_factory->widgets[$widget]) ? $wp_widget_factory->widgets[$widget] : false;
     if (empty($the_widget)) {
         return;
     }
     if (!empty($value)) {
         $value['widget_id_base'] = $the_widget->id_base;
         $value['number'] = isset($value['number']) ? $value['number'] : uniqid();
         $value['widget_id'] = $value['widget_id_base'] . '-' . $value['number'];
         $value['instance'] = array();
         $value['the_widget'] = $widget;
         if (isset($value['widget_fields']) && class_exists($widget) && method_exists($widget, 'update')) {
             $the_widget = new $widget();
             $value['instance'] = $the_widget->update($value['widget_fields'], $value['widget_fields']);
         }
         unset($value['widget_fields']);
         // update sub fields
         if (!$field['sub_fields']) {
             return $value;
         }
         foreach ($field['sub_fields'] as $sub_field) {
             $v = false;
             if (isset($value[$sub_field['key']])) {
                 $v = $value[$sub_field['key']];
             } elseif (isset($value[$sub_field['name']])) {
                 $v = $value[$sub_field['name']];
             } else {
                 // input is not set (hidden by conditioanl logic)
                 continue;
             }
             //Save ACF Widget Fields using a mock widget ID
             acf_update_value($v, 'widget_' . $value['widget_id'], $sub_field);
             // modify name for save
             $sub_field['name'] = "{$field['name']}_{$sub_field['name']}";
             // update value
             acf_update_value($v, $post_id, $sub_field);
         }
     }
     return $value;
 }
开发者ID:lucasstark,项目名称:acf-field-a-widget,代码行数:44,代码来源:acf-a_widget-v5.php


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