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


PHP acf_get_value函数代码示例

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


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

示例1: acf_views_render_fields

function acf_views_render_fields($post_id = 0, $fields, $el = 'div', $instruction = 'label')
{
    // bail early if no fields
    if (empty($fields)) {
        return false;
    }
    // remove corrupt fields
    $fields = array_filter($fields);
    //Load all the values first
    foreach ($fields as &$ref_field) {
        // load value
        if ($ref_field['value'] === null) {
            $ref_field['value'] = acf_get_value($post_id, $ref_field);
        }
    }
    $hiding_fields = false;
    // loop through fields
    foreach ($fields as $field) {
        // load value
        if ($field['value'] === null) {
            $field['value'] = acf_get_value($post_id, $field);
        }
        // set prefix for correct post name (prefix + key)
        $field['prefix'] = 'acf';
        // render
        $show_field = true;
        if (!empty($field['conditional_logic'])) {
            $show_field = ACF_Views_Conditional_Logic::show_field($field, $fields);
        }
        if ($field['type'] == 'tab') {
            if (!$show_field) {
                $hiding_fields = true;
            } else {
                $hiding_fields = false;
            }
        }
        if (!$hiding_fields) {
            if ($show_field) {
                if ($field['type'] == 'repeater') {
                    $x = 1;
                }
                acf_views_render_field_wrap($field, $el, $instruction);
            }
        }
    }
}
开发者ID:NikolaGrdanjski,项目名称:acf-views,代码行数:46,代码来源:acf-views-api.php

示例2: acf_render_fields

function acf_render_fields($post_id = 0, $fields, $el = 'div', $instruction = 'label')
{
    if (!empty($fields)) {
        foreach ($fields as $field) {
            // load value
            if ($field['value'] === null) {
                $field['value'] = acf_get_value($post_id, $field);
            }
            // set prefix for correct post name (prefix + key)
            $field['prefix'] = 'acf';
            // render
            acf_render_field_wrap($field, $el, $instruction);
        }
    }
}
开发者ID:quangnpd,项目名称:jobshop_web,代码行数:15,代码来源:api-field.php

示例3: load_value

 function load_value($value, $post_id, $field)
 {
     $fields = array();
     foreach ($field['sub_fields'] as $sub_field) {
         $sub_field_name = $sub_field['name'];
         // update prefix to allow for nested values
         $sub_field['prefix'] = $field["name"];
         $sub_field['name'] = "{$field['name']}_{$sub_field_name}";
         // load value
         if ($sub_field['value'] === null) {
             $sub_field['value'] = acf_format_value(acf_get_value($post_id, $sub_field), $post_id, $sub_field);
         }
         $fields[$sub_field_name] = $sub_field['value'];
     }
     return $fields;
 }
开发者ID:devgeniem,项目名称:acf-reusable-field-group,代码行数:16,代码来源:acf-reusable_field_group-v5.php

示例4: get_field_object

function get_field_object($selector, $post_id = false, $format_value = true, $load_value = true)
{
    // complete loading
    acf()->complete();
    // compatibilty
    if (is_array($format_value)) {
        $format_value = acf_parse_args($format_value, array('format_value' => true, 'load_value' => true));
        extract($format_value);
    }
    // vars
    $override_name = false;
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // load field reference if not a field_key
    if (!acf_is_field_key($selector)) {
        $override_name = $selector;
        $selector = acf_get_field_reference($selector, $post_id);
    }
    // get field key
    $field = acf_get_field($selector);
    // bail early if no field found
    if (!$field) {
        return false;
    }
    // override name?
    // This allows the $selector to be a sub field (images_0_image)
    if ($override_name) {
        $field['name'] = $override_name;
    }
    // load value
    if ($load_value) {
        $field['value'] = acf_get_value($post_id, $field);
    }
    // format value
    if ($format_value) {
        // get value for field
        $field['value'] = acf_format_value($field['value'], $post_id, $field);
    }
    // return
    return $field;
}
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:41,代码来源:api-template.php

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

示例6: display_field_column

        function display_field_column($column, $post_id)
        {
            if (isset($this->column_fields[$column])) {
                $field = $this->column_fields[$column];
                switch ($field['type']) {
                    case 'file':
                        $value = acf_get_value($post_id, $field);
                        if (!is_null($value) && !empty($value)) {
                            $file = get_post($value);
                            printf(__('Edit: <a href="%s">%s</a>', 'acf-quick-edit-fields'), get_edit_post_link($value), $file->post_title);
                        }
                        break;
                    case 'image':
                        $image_id = get_field($field['key']);
                        if ($image_id) {
                            if (is_array($image_id)) {
                                // Image field is an object
                                echo wp_get_attachment_image($image_id['id'], array(80, 80));
                            } else {
                                if (is_numeric($image_id)) {
                                    // Image field is an ID
                                    echo wp_get_attachment_image($image_id, array(80, 80));
                                } else {
                                    // Image field is a url
                                    echo '<img src="' . $image_id . '" width="80" height="80" />';
                                }
                            }
                        }
                        break;
                    case 'select':
                    case 'radio':
                    case 'checkbox':
                        $field_value = get_field($field['key']);
                        $values = array();
                        foreach ((array) $field_value as $value) {
                            $values[] = isset($field['choices'][$value]) ? $field['choices'][$value] : $value;
                        }
                        $output = implode(__(', ', 'acf-quick-edit-fields'), $values);
                        if (empty($output)) {
                            $output = __('(No value)', 'acf-quick-edit-fields');
                        }
                        echo $output;
                        break;
                    case 'true_false':
                        echo get_field($field['key']) ? __('Yes') : __('No');
                        break;
                    case 'color_picker':
                        $value = get_field($field['key']);
                        if ($value) {
                            echo '<div class="color-indicator" style="border-radius:2px;border:1px solid #d2d2d2;width:26px;height:20px;background-color:' . $value . '"></div>';
                        } else {
                            _e('(No value)', 'acf-quick-edit-fields');
                        }
                        break;
                    case 'number':
                        $value = get_field($field['key']);
                        if ($value === "") {
                            _e('(No value)', 'acf-quick-edit-fields');
                        } else {
                            echo number_format_i18n($value, strlen(substr(strrchr($value, "."), 1)));
                        }
                        break;
                    case 'textarea':
                        ?>
<pre><?php 
                        the_field($field['key']);
                        ?>
</pre><?php 
                        break;
                    default:
                        the_field($field['key']);
                        break;
                }
            }
        }
开发者ID:kirstyburgoine,项目名称:acf-quick-edit-fields,代码行数:75,代码来源:index.php

示例7: load_value

 function load_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value) || empty($field['layouts'])) {
         return $value;
     }
     // value must be an array
     $value = acf_get_array($value);
     // vars
     $rows = array();
     // populate $layouts
     $layouts = array();
     foreach (array_keys($field['layouts']) as $i) {
         // get layout
         $layout = $field['layouts'][$i];
         // append to $layouts
         $layouts[$layout['name']] = $layout['sub_fields'];
     }
     // loop through rows
     foreach ($value as $i => $l) {
         // append to $values
         $rows[$i] = array();
         $rows[$i]['acf_fc_layout'] = $l;
         // bail early if layout deosnt contain sub fields
         if (empty($layouts[$l])) {
             continue;
         }
         // get layout
         $layout = $layouts[$l];
         // loop through sub fields
         foreach (array_keys($layout) as $j) {
             // get sub field
             $sub_field = $layout[$j];
             // update full name
             $sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
             // get value
             $sub_value = acf_get_value($post_id, $sub_field);
             // add value
             $rows[$i][$sub_field['key']] = $sub_value;
         }
         // foreach
     }
     // foreach
     // return
     return $rows;
 }
开发者ID:Aqro,项目名称:NewDWM,代码行数:46,代码来源:flexible-content.php

示例8: load_value

 function load_value($value, $post_id, $field)
 {
     // bail early if no sub fields
     if (empty($field['sub_fields'])) {
         return $value;
     }
     // modify
     $field = $this->prepare_field_for_save($field);
     // load sub fields
     $value = array();
     // loop
     foreach (array_keys($field['sub_fields']) as $i) {
         // get sub field
         $sub_field = $field['sub_fields'][$i];
         // get value
         $sub_value = acf_get_value($post_id, $sub_field);
         // add value
         $value[$sub_field['key']] = $sub_value;
     }
     // return
     return $value;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:22,代码来源:clone.php

示例9: _extract_strings

 /**
  * Extract translatable items from the $field_group
  *
  * Supported Field Types:
  * - Basic
  *   - text
  *   - textarea
  *   - number
  *   - email
  *   - url
  *   - password
  * - Content
  *   - wysiwyg
  *   - oembed
  *   - image
  *   - file
  *   - gallery (pro)
  * - Choice
  *   - select
  *   - checkbox
  *   - radio
  *   - true_false
  * - Relational
  *   - post_object
  *   - page_link
  *   - relationship
  *   - taxonomy
  *   - user
  * - jQuery
  *   - google_map
  *   - date_picker
  *   - color_picker
  * - Layout
  *   - message
  *   - tab
  *   - repeater (pro)
  *   - flexible_content (pro)
  *
  * Unsupported Field Types:
  * - N/A
  *
  * @todo    Register custom locations, fields, and field types.
  *
  * @param   mixed        $field_group
  * @param   array        $data
  * @param   string|bool  $sub_fields
  * @return  array        $data
  */
 protected function _extract_strings($field_group, &$data = [], $sub_fields = false)
 {
     $is_options_group = $this->is_options_group($field_group);
     if ($sub_fields) {
         $fields = isset($field_group['sub_fields']) ? $field_group['sub_fields'] : $field_group;
         $_prefix = is_string($sub_fields) ? $sub_fields : '';
     } else {
         $group_keys = $this->_get_group_keys();
         $this->pluck_strings($field_group, $group_keys, $data);
         $fields = $field_group['fields'];
         $_prefix = '';
     }
     if (!empty($fields)) {
         $field_keys = $this->_get_field_keys();
         foreach ($fields as $i => $field) {
             $prefix = $_prefix . $field['key'] . '.';
             $value_keys = $this->_get_value_keys($field);
             $this->pluck_strings($field, $field_keys, $data, $prefix);
             if ($is_options_group) {
                 if ($field['value'] === null) {
                     $field['value'] = acf_get_value('options', $field);
                 }
                 $this->pluck_strings($field, $value_keys, $data, $prefix);
             }
             $prefix = '';
             switch ($field['type']) {
                 case 'text':
                 case 'textarea':
                 case 'number':
                 case 'email':
                 case 'url':
                 case 'password':
                 case 'select':
                     if (isset($field['placeholder']) && '' != $field['placeholder']) {
                         $data[$_prefix . $field['key'] . '.placeholder'] = ['string' => $field['placeholder'], 'multiline' => 'textarea' === $field['type']];
                     }
                 case 'text':
                 case 'textarea':
                 case 'number':
                 case 'email':
                 case 'url':
                 case 'password':
                     $affix_keys = $this->_get_affix_keys();
                     foreach ($affix_keys as $key) {
                         if (isset($field[$key]) && '' != $field[$key]) {
                             $data[$_prefix . $field['key'] . '.' . $key] = ['string' => $field[$key], 'multiline' => false];
                         }
                     }
                     break;
                 case 'true_false':
                 case 'message':
                     if (isset($field['message']) && '' != $field['message']) {
//.........这里部分代码省略.........
开发者ID:locomotivemtl,项目名称:wordpress-boilerplate,代码行数:101,代码来源:acf.php

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

示例11: display_field_column

 function display_field_column($column, $post_id)
 {
     if (isset($this->column_fields[$column])) {
         $field = $this->column_fields[$column];
         switch ($field['type']) {
             case 'file':
                 $value = \acf_get_value($post_id, $field);
                 if (!is_null($value) && !empty($value)) {
                     $file = \get_post($value);
                     printf(__('Edit: %s', 'acf-quick-edit-fields'), sprintf('<a href="%s" title="%s">%s</a>', \esc_url(\get_edit_post_link($value)), \esc_attr($file->post_title), $file->post_title));
                 }
                 break;
             case 'image':
                 $image_id = \get_field($field['key']);
                 if (!$image_id) {
                     return;
                 }
                 if (is_array($image_id)) {
                     // Image field is an object
                     echo \wp_get_attachment_image($image_id['id'], array(80, 80));
                 } else {
                     if (is_numeric($image_id)) {
                         // Image field is an ID
                         echo \wp_get_attachment_image($image_id, array(80, 80));
                     } else {
                         // Image field is a url
                         echo '<img src="' . $image_id . '" width="80" height="80" />';
                     }
                 }
                 break;
             case 'select':
                 $field_value = \get_field($field['key']);
                 if (is_array($field_value)) {
                     \_e('(Default value)', 'acf-quick-edit-fields');
                 } else {
                     if (isset($field['choices'][$field_value])) {
                         echo $field['choices'][$field_value];
                     }
                 }
             case 'radio':
             case 'checkbox':
                 $field_value = \get_field($field['key']);
                 $values = array();
                 foreach ((array) $field_value as $value) {
                     $values[] = isset($field['choices'][$value]) ? $field['choices'][$value] : $value;
                 }
                 $output = implode(\__(', ', 'acf-quick-edit-fields'), $values);
                 if (empty($output)) {
                     $output = \__('(No value)', 'acf-quick-edit-fields');
                 }
                 echo $output;
                 break;
             case 'true_false':
                 $true_false = \get_field($field['key']);
                 $formatted = $true_false ? __('Yes', 'acf-quick-edit-fields') : __('No', 'acf-quick-edit-fields');
                 echo \apply_filters('acf/quick_edit/field_column/true_false', $formatted, $true_false, $post_id);
                 break;
             case 'post_object':
                 $post_object = \get_field($field['key']);
                 $post_title = '';
                 if (is_object($post_object)) {
                     $post_title = \get_the_title($post_object->ID);
                 }
                 echo \apply_filters('acf/quick_edit/field_column/post_object', $post_title, $post_object, $post_id);
                 break;
             case 'date_picker':
                 $date = \get_field($field['key']);
                 echo \apply_filters('acf/quick_edit/field_column/date_picker', date_i18n($field['display_format'], strtotime($date)), $date, $post_id);
                 break;
             case 'color_picker':
                 $value = \get_field($field['key']);
                 if ($value) {
                     echo '<div class="color-indicator" style="border-radius:2px;border:1px solid #d2d2d2;width:26px;height:20px;background-color:' . $value . '"></div>';
                 } else {
                     \_e('(No value)', 'acf-quick-edit-fields');
                 }
                 break;
             case 'number':
                 $value = \get_field($field['key']);
                 if ($value === '') {
                     \_e('(No value)', 'acf-quick-edit-fields');
                 } else {
                     echo \number_format_i18n($value, strlen(substr(strrchr($value, '.'), 1)));
                 }
                 break;
             case 'textarea':
                 printf('<pre>%s</pre>', \get_field($field['key']));
                 break;
             default:
                 echo \get_field($field['key']);
                 break;
         }
     }
 }
开发者ID:s3rgiosan,项目名称:acf-quick-edit-fields,代码行数:94,代码来源:index.php

示例12: load_value

 public function load_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value) || !isset($field['sub_fields']) || empty($field['sub_fields'])) {
         return $value;
     }
     // loop through sub fields
     foreach (array_keys($field['sub_fields']) as $j) {
         // get sub field
         $sub_field = $field['sub_fields'][$j];
         if (isset($value['widget_id']) && !empty($value['widget_id'])) {
             $acf_widget_api_key = 'widget_' . $value['widget_id'];
             $sub_value = acf_get_value($acf_widget_api_key, $sub_field);
         } else {
             $sub_value = null;
         }
         //Store the value so we don't have to reterive it again in the render function.
         $value[$sub_field['key']] = $sub_value;
     }
     return $value;
 }
开发者ID:lucasstark,项目名称:acf-field-a-widget,代码行数:21,代码来源:acf-a_widget-v5.php

示例13: delete_row

function delete_row($selector, $row = 1, $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 value
    $rows = acf_get_value($post_id, $field);
    // bail early if no value
    if (empty($rows)) {
        return false;
    }
    // vars
    $i = $row - 1;
    // bail early if row doesn't exist
    if (empty($rows[$i])) {
        return false;
    }
    // unset
    unset($rows[$i]);
    // reindex
    $rows = array_values($rows);
    // update
    acf_update_value($rows, $post_id, $field);
    // return
    return true;
}
开发者ID:Garth619,项目名称:Femi9,代码行数:31,代码来源:api-template.php

示例14: display_field_column

 function display_field_column($column, $post_id)
 {
     if (isset($this->column_fields[$column])) {
         $field = $this->column_fields[$column];
         switch ($field['type']) {
             case 'file':
                 $value = acf_get_value($post_id, $field);
                 if (!is_null($value) && !empty($value)) {
                     $file = get_post($value);
                     printf(__('Edit: <a href="%s">%s</a>', 'acf-quick-edit-fields'), get_edit_post_link($value), $file->post_title);
                 }
                 break;
             case 'image':
                 $image_id = get_field($field['key']);
                 if (is_array($image_id)) {
                     // Image field is an object
                     echo wp_get_attachment_image($image_id['id'], array(80, 80));
                 } else {
                     if (is_numeric($image_id)) {
                         // Image field is an ID
                         echo wp_get_attachment_image($image_id, array(80, 80));
                     } else {
                         // Image field is a url
                         echo '<img src="' . $image_id . '" width="80" height="80" />';
                     }
                 }
                 break;
             case 'select':
                 $field_value = get_field($field['key']);
                 //
                 if (is_array($field_value)) {
                     _e('(Default value)', 'acf-quick-edit-fields');
                 } else {
                     if (isset($field['choices'][$field_value])) {
                         echo $field['choices'][get_field($field['key'])];
                     }
                 }
                 break;
             case 'true_false':
                 echo get_field($field['key']) ? __('Yes') : __('No');
                 break;
             default:
                 the_field($field['key']);
                 break;
         }
     }
 }
开发者ID:vahem2lu,项目名称:acf-quick-edit-fields,代码行数:47,代码来源:index.php

示例15: 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_value($post_id, $field, true);
     $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:slavic18,项目名称:cats,代码行数:77,代码来源:flexible-content.php


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