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


PHP acf_get_array函数代码示例

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


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

示例1: render_field

 function render_field($field)
 {
     // decode value (convert to array)
     $field['value'] = acf_get_array($field['value'], false);
     // hiden input
     acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
     // vars
     $i = 0;
     $li = '';
     $all_checked = true;
     // checkbox saves an array
     $field['name'] .= '[]';
     // foreach choices
     if (!empty($field['choices'])) {
         foreach ($field['choices'] as $value => $label) {
             // increase counter
             $i++;
             // vars
             $atts = array('type' => 'checkbox', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value);
             // is choice selected?
             if (in_array($value, $field['value'])) {
                 $atts['checked'] = 'checked';
             } else {
                 $all_checked = false;
             }
             if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) {
                 $atts['disabled'] = 'disabled';
             }
             // each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute
             if ($i > 1) {
                 $atts['id'] .= '-' . $value;
             }
             // append HTML
             $li .= '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>';
         }
         // toggle all
         if ($field['toggle']) {
             // vars
             $label = __("Toggle All", 'acf');
             $atts = array('type' => 'checkbox', 'class' => 'acf-checkbox-toggle');
             // custom label
             if (is_string($field['toggle'])) {
                 $label = $field['toggle'];
             }
             // checked
             if ($all_checked) {
                 $atts['checked'] = 'checked';
             }
             // append HTML
             $li = '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>' . $li;
         }
     }
     // class
     $field['class'] .= ' acf-checkbox-list';
     $field['class'] .= $field['layout'] == 'horizontal' ? ' acf-hl' : ' acf-bl';
     // return
     echo '<ul ' . acf_esc_attr(array('class' => $field['class'])) . '>' . $li . '</ul>';
 }
开发者ID:ReLiFeD,项目名称:irreversible.eu,代码行数:58,代码来源:checkbox.php

示例2: format_value

 public function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_get_array($value);
     // convert values to int
     $value = array_map('intval', $value);
     // load posts if needed
     if ($field['return_format'] == 'object') {
         $value = ACF_API_Fields()->api->get_posts($field, array('include' => $value));
     }
     // convert back from array if neccessary
     if (!$field['multiple']) {
         $value = array_shift($value);
     }
     // return value
     return $value;
 }
开发者ID:NiviJah,项目名称:acf-api-fields,代码行数:21,代码来源:class-acf-api-fields-field-relationship.php

示例3: update_value

 function update_value($value, $post_id, $field)
 {
     // validate
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_get_array($value);
     // array
     foreach ($value as $k => $v) {
         // object?
         if (is_object($v) && isset($v->ID)) {
             $value[$k] = $v->ID;
         }
     }
     // save value as strings, so we can clearly search for them in SQL LIKE statements
     $value = array_map('strval', $value);
     // return
     return $value;
 }
开发者ID:bself,项目名称:nuimage-wp,代码行数:20,代码来源:relationship.php

示例4: update_value

 function update_value($value, $post_id, $field)
 {
     if ($post_id === $GLOBALS['post_id']) {
         $new_value = $this->clean_post_value($value);
         $old_value = $this->clean_post_value(get_field($field['key']));
         $new_values = array();
         $missing_values = array();
         if (!empty($new_value) && !empty($old_value)) {
             $new_values = array_diff($new_value, $old_value);
             $missing_values = array_diff($old_value, $new_value);
         } else {
             if (!empty($new_value)) {
                 $new_values = array_map('strval', $new_value);
             }
             if (!empty($old_value)) {
                 $missing_values = array_map('strval', $old_value);
             }
         }
         foreach ($new_values as $value_add) {
             $existing_value = get_field($field['key'], $value_add);
             if (!empty($existing_value)) {
                 $existing_value[] = $post_id;
             } else {
                 $existing_value = array($post_id);
             }
             update_field($field['key'], $existing_value, $value_add);
         }
         foreach ($missing_values as $value_remove) {
             $existing_value = get_field($field['key'], $value_remove);
             if (!empty($existing_value)) {
                 if ($existing_value[0] instanceof WP_Post) {
                     $old_existing_value = $existing_value;
                     $existing_value = array();
                     foreach ($old_existing_value as $post) {
                         if ($post->ID !== $post_id) {
                             $existing_value[] = $post;
                         }
                     }
                 } else {
                     $existing_value = array_diff($existing_val, array($post_id));
                 }
                 update_field($field['key'], $existing_value, $value_remove);
             }
         }
     }
     // validate
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_get_array($value);
     // array
     foreach ($value as $k => $v) {
         // object?
         if (is_object($v) && isset($v->ID)) {
             $value[$k] = $v->ID;
         }
     }
     // save value as strings, so we can clearly search for them in SQL LIKE statements
     $value = array_map('strval', $value);
     // return
     return $value;
 }
开发者ID:62design,项目名称:acf-2way-pr,代码行数:63,代码来源:acf-2way-pr-v5.php

示例5: render_field

 function render_field($field)
 {
     $taxonomies = array();
     $taxonomies = acf_get_array($taxonomies);
     $taxonomies = acf_get_pretty_taxonomies($taxonomies);
     $taxonomy_terms = acf_get_taxonomy_terms();
     $selected_taxonomies = array();
     $terms = array();
     $slug_name = !empty($field['choices']) ? $field['choices'] : array_keys(acf_get_pretty_taxonomies());
     if ($field['tax_type'] == 'Term') {
         // select terms
         foreach ($slug_name as $k1 => $v1) {
             $terms = array_merge($terms, get_terms($v1, array('hide_empty' => false)));
             foreach ($taxonomies as $k2 => $v2) {
                 if ($v1 == $k2) {
                     $field['choices'][$k1] = $v2;
                 }
             }
         }
         foreach ($field['choices'] as $k1 => $v1) {
             foreach ($taxonomy_terms as $k2 => $v2) {
                 if ($v1 == $k2) {
                     $selected_taxonomies[$v1] = $taxonomy_terms[$k2];
                 }
             }
         }
     } else {
         //select taxonomies
         $taxonomies = array();
         foreach ($slug_name as $tax_name) {
             // only use allowed taxonomies
             $taxonomies[$tax_name] = get_taxonomy($tax_name);
         }
         foreach ($taxonomies as $taxonomy) {
             $selected_taxonomies[$taxonomy->name] = $taxonomy->label;
         }
     }
     $field['choices'] = $selected_taxonomies;
     // add empty value (allows '' to be selected)
     if (empty($field['value'])) {
         $field['value'] = '';
         $field['value']['cat'] = '';
     }
     // placeholder
     if (empty($field['placeholder'])) {
         $field['placeholder'] = __("Select", 'acf');
     }
     // vars
     $atts = array('id' => $field['id'], 'class' => $field['class'] . ' js-multi-taxonomy-select2', 'name' => $field['name'], 'data-ui' => $field['ui'], 'data-ajax' => $field['ajax'], 'data-placeholder' => $field['placeholder'], 'data-allow_null' => $field['allow_null']);
     // hidden input
     if ($field['ui']) {
         acf_hidden_input(array('type' => 'hidden', 'id' => $field['id'], 'name' => $field['name'], 'value' => implode(',', $field['value'])));
     } elseif ($field['multiple']) {
         acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
     }
     // ui
     if ($field['ui']) {
         $atts['disabled'] = 'disabled';
         $atts['class'] .= ' acf-hidden';
     }
     // special atts
     foreach (array('readonly', 'disabled') as $k) {
         if (!empty($field[$k])) {
             $atts[$k] = $k;
         }
     }
     // vars
     $els = array();
     $choices = array();
     // loop through values and add them as options
     if (!empty($field['choices'])) {
         foreach ($field['choices'] as $k => $v) {
             // allowed taxonomies
             if (is_array($v)) {
                 // optgroup
                 $els[] = array('type' => 'optgroup', 'label' => $k);
                 if (!empty($v)) {
                     foreach ($v as $k2 => $v2) {
                         $strip_v2_hyphen = preg_replace('#-\\s?#', '', $v2);
                         // Child categories have hyphens before the name, we need to remove them in order to match them
                         if ($field['type_value']) {
                             // value = term ID
                             foreach ($terms as $key => $val) {
                                 if ($val->name == $strip_v2_hyphen) {
                                     $els[] = array('type' => 'option', 'value' => $val->term_id, 'label' => $v2, 'selected' => $slct = $val->term_id == $field['value'] ? "selected" : "");
                                 }
                             }
                         } else {
                             // value = term slug
                             preg_match('#(?::)(.*)#', $k2, $value);
                             // originally returns 'taxonomy:term-slug' this removes 'taxonomy:'
                             $els[] = array('type' => 'option', 'value' => $value[1], 'label' => $v2, 'selected' => $slct = $value[1] == $field['value'] ? "selected" : "");
                         }
                         $choices[] = $k2;
                     }
                 }
                 $els[] = array('type' => '/optgroup');
             } else {
                 // value = Taxonomy Slug
                 $els[] = array('type' => 'option', 'value' => $k, 'label' => $v, 'selected' => $slct = $k == $field['value'] ? "selected" : "");
//.........这里部分代码省略.........
开发者ID:marktimemedia,项目名称:acf-term-and-taxonomy-chooser,代码行数:101,代码来源:acf-taxonomy-chooser-v5.php

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

示例7: acf_get_valid_terms

function acf_get_valid_terms($terms = false, $taxonomy = 'category')
{
    // bail early if function does not yet exist or
    if (!function_exists('wp_get_split_term') || empty($terms)) {
        return $terms;
    }
    // vars
    $is_array = is_array($terms);
    // force into array
    $terms = acf_get_array($terms);
    // force ints
    $terms = array_map('intval', $terms);
    // attempt to find new terms
    foreach ($terms as $i => $term_id) {
        $new_term_id = wp_get_split_term($term_id, $taxonomy);
        if ($new_term_id) {
            $terms[$i] = $new_term_id;
        }
    }
    // revert array if needed
    if (!$is_array) {
        $terms = $terms[0];
    }
    // return
    return $terms;
}
开发者ID:finestpixels,项目名称:foodbytes2016,代码行数:26,代码来源:api-helpers.php

示例8: get_clone_setting_choices

 function get_clone_setting_choices($value)
 {
     // vars
     $choices = array();
     // bail early if no $value
     if (empty($value)) {
         return $choices;
     }
     // force value to array
     $value = acf_get_array($value);
     // loop
     foreach ($value as $v) {
         $choices[$v] = $this->get_clone_setting_choice($v);
     }
     // return
     return $choices;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:17,代码来源:clone.php

示例9: render_field

 function render_field($field)
 {
     // convert value to array
     $field['value'] = acf_get_array($field['value'], false);
     // add empty value (allows '' to be selected)
     if (empty($field['value'])) {
         $field['value'][''] = '';
     }
     // placeholder
     if (empty($field['placeholder'])) {
         $field['placeholder'] = __("Select", 'acf');
     }
     // vars
     $atts = array('id' => $field['id'], 'class' => $field['class'], 'name' => $field['name'], 'data-ui' => $field['ui'], 'data-ajax' => $field['ajax'], 'data-multiple' => $field['multiple'], 'data-placeholder' => $field['placeholder'], 'data-allow_null' => $field['allow_null']);
     // ui
     if ($field['ui']) {
         $atts['disabled'] = 'disabled';
         $atts['class'] .= ' acf-hidden';
     }
     // multiple
     if ($field['multiple']) {
         $atts['multiple'] = 'multiple';
         $atts['size'] = 5;
         $atts['name'] .= '[]';
     }
     // special atts
     foreach (array('readonly', 'disabled') as $k) {
         if (!empty($field[$k])) {
             $atts[$k] = $k;
         }
     }
     // vars
     $els = array();
     $choices = array();
     // loop through values and add them as options
     if (!empty($field['choices'])) {
         foreach ($field['choices'] as $k => $v) {
             if (is_array($v)) {
                 // optgroup
                 $els[] = array('type' => 'optgroup', 'label' => $k);
                 if (!empty($v)) {
                     foreach ($v as $k2 => $v2) {
                         $els[] = array('type' => 'option', 'value' => $k2, 'label' => $v2, 'selected' => in_array($k2, $field['value']));
                         $choices[] = $k2;
                     }
                 }
                 $els[] = array('type' => '/optgroup');
             } else {
                 $els[] = array('type' => 'option', 'value' => $k, 'label' => $v, 'selected' => in_array($k, $field['value']));
                 $choices[] = $k;
             }
         }
     }
     // hidden input
     if ($field['ui']) {
         // restirct value
         $v = array_intersect($field['value'], $choices);
         if ($field['multiple']) {
             $v = implode('||', $v);
         } else {
             $v = acf_maybe_get($v, 0, '');
         }
         acf_hidden_input(array('type' => 'hidden', 'id' => $field['id'] . '-input', 'name' => $field['name'], 'value' => $v));
     } elseif ($field['multiple']) {
         acf_hidden_input(array('type' => 'hidden', 'id' => $field['id'] . '-input', 'name' => $field['name']));
     }
     // null
     if ($field['allow_null']) {
         array_unshift($els, array('type' => 'option', 'value' => '', 'label' => '- ' . $field['placeholder'] . ' -'));
     }
     // html
     echo '<select ' . acf_esc_attr($atts) . '>';
     // construct html
     if (!empty($els)) {
         foreach ($els as $el) {
             // extract type
             $type = acf_extract_var($el, 'type');
             if ($type == 'option') {
                 // get label
                 $label = acf_extract_var($el, 'label');
                 // validate selected
                 if (acf_extract_var($el, 'selected')) {
                     $el['selected'] = 'selected';
                 }
                 // echo
                 echo '<option ' . acf_esc_attr($el) . '>' . $label . '</option>';
             } else {
                 // echo
                 echo '<' . $type . ' ' . acf_esc_attr($el) . '>';
             }
         }
     }
     echo '</select>';
 }
开发者ID:de190909,项目名称:WPTest,代码行数:94,代码来源:select.php

示例10: render_field

 public function render_field($field)
 {
     // convert value to array
     $field['value'] = acf_get_array($field['value'], false);
     // add empty value (allows '' to be selected)
     if (empty($field['value'])) {
         $field['value'][''] = '';
     }
     // placeholder
     if (empty($field['placeholder'])) {
         $field['placeholder'] = __("Select", 'acf');
     }
     // vars
     $atts = array('id' => $field['id'], 'class' => $field['class'], 'name' => $field['name'], 'data-multiple' => $field['multiple'], 'data-placeholder' => $field['placeholder'], 'data-allow_null' => $field['allow_null']);
     // multiple
     if ($field['multiple']) {
         $atts['multiple'] = 'multiple';
         $atts['size'] = 5;
         $atts['name'] .= '[]';
     }
     // special atts
     foreach (array('readonly', 'disabled') as $k) {
         if (!empty($field[$k])) {
             $atts[$k] = $k;
         }
     }
     // vars
     $els = array();
     // $choices = array();
     $posttypes = $this->post_type_options();
     foreach ($posttypes as $pt) {
         $els[] = array('type' => 'option', 'value' => $pt['value'], 'label' => $pt['label'], 'selected' => in_array($pt['value'], $field['value']));
     }
     // null
     if ($field['allow_null']) {
         array_unshift($els, array('type' => 'option', 'value' => '', 'label' => '- ' . $field['placeholder'] . ' -'));
     }
     // html
     echo '<select ' . acf_esc_attr($atts) . '>';
     // construct html
     if (!empty($els)) {
         foreach ($els as $el) {
             // extract type
             $type = acf_extract_var($el, 'type');
             if ($type == 'option') {
                 // get label
                 $label = acf_extract_var($el, 'label');
                 // validate selected
                 if (acf_extract_var($el, 'selected')) {
                     $el['selected'] = 'selected';
                 }
                 // echo
                 echo '<option ' . acf_esc_attr($el) . '>' . $label . '</option>';
             } else {
                 // echo
                 echo '<' . $type . ' ' . acf_esc_attr($el) . '>';
             }
         }
     }
     echo '</select>';
 }
开发者ID:helsingborg-stad,项目名称:Modularity,代码行数:61,代码来源:acf-posttype-select-v5.php

示例11: display_quickedit_field

        function display_quickedit_field($column, $post_type, $field)
        {
            ?>
<fieldset class="inline-edit-col-left inline-edit-<?php 
            echo $post_type;
            ?>
"><?php 
            ?>
<div class="inline-edit-col column-<?php 
            echo $column;
            ?>
"><?php 
            ?>
<label class="inline-edit-group"><?php 
            ?>
<span class="title"><?php 
            echo $field['label'];
            ?>
</span><?php 
            ?>
<span class="input-text-wrap"><?php 
            $input_atts = array('data-acf-field-key' => $field['key'], 'name' => $this->post_field_prefix . $column);
            switch ($field['type']) {
                case 'checkbox':
                    $input_atts += array('class' => 'acf-quick-edit', 'id' => $this->post_field_prefix . $column);
                    $field['value'] = \acf_get_array($field['value'], false);
                    $input_atts['name'] .= '[]';
                    foreach ($field['choices'] as $value => $label) {
                        $atts = array('type' => 'checkbox', 'value' => $value) + $input_atts;
                        if (in_array($value, $field['value'])) {
                            $atts['checked'] = 'checked';
                        } else {
                            $all_checked = false;
                        }
                        $atts['id'] .= '-' . $value;
                        echo '<label><input ' . \acf_esc_attr($atts) . '/>' . $label . '</label>';
                    }
                    break;
                case 'select':
                    $input_atts += array('class' => 'acf-quick-edit widefat', 'id' => $this->post_field_prefix . $column);
                    if ($field['multiple']) {
                        $input_atts['multiple'] = 'multiple';
                    }
                    ?>
<select <?php 
                    echo \acf_esc_attr($input_atts);
                    ?>
><?php 
                    if ($field['allow_null']) {
                        echo '<option value="">' . '- ' . \__('Select', 'acf-quick-edit-fields') . ' -';
                    }
                    foreach ($field['choices'] as $name => $label) {
                        echo '<option value="' . $name . '">' . $label;
                    }
                    ?>
</select><?php 
                    break;
                case 'radio':
                    ?>
<ul class="acf-radio-list<?php 
                    echo $field['other_choice'] ? ' other' : '';
                    ?>
" data-acf-field-key="<?php 
                    echo $field['key'];
                    ?>
"><?php 
                    foreach ($field['choices'] as $name => $value) {
                        ?>
<li><label for="<?php 
                        echo $this->post_field_prefix . $column . '-' . $name;
                        ?>
"><?php 
                        ?>
<input id="<?php 
                        echo $this->post_field_prefix . $column . '-' . $name;
                        ?>
" type="radio" value="<?php 
                        echo $name;
                        ?>
"
										  class="acf-quick-edit" data-acf-field-key="<?php 
                        echo $field['key'];
                        ?>
"
										  name="<?php 
                        echo $this->post_field_prefix . $column;
                        ?>
" /><?php 
                        echo $value;
                        ?>
</label></li><?php 
                    }
                    if ($field['other_choice']) {
                        ?>
<li><label for="<?php 
                        echo $this->post_field_prefix . $column . '-other';
                        ?>
"><?php 
                        ?>
<input id="<?php 
//.........这里部分代码省略.........
开发者ID:s3rgiosan,项目名称:acf-quick-edit-fields,代码行数:101,代码来源:index.php

示例12: acf_get_post_types

if ($width['post_type']) {
    if (!empty($field['post_type'])) {
        $post_types = $field['post_type'];
    } else {
        $post_types = acf_get_post_types();
    }
    $post_types = acf_get_pretty_post_types($post_types);
}
// taxonomy filter
$taxonomies = array();
$term_groups = array();
if ($width['taxonomy']) {
    // taxonomies
    if (!empty($field['taxonomy'])) {
        // get the field's terms
        $term_groups = acf_get_array($field['taxonomy']);
        $term_groups = acf_decode_taxonomy_terms($term_groups);
        // update taxonomies
        $taxonomies = array_keys($term_groups);
    } elseif (!empty($field['post_type'])) {
        // loop over post types and find connected taxonomies
        foreach ($field['post_type'] as $post_type) {
            $post_taxonomies = get_object_taxonomies($post_type);
            // bail early if no taxonomies
            if (empty($post_taxonomies)) {
                continue;
            }
            foreach ($post_taxonomies as $post_taxonomy) {
                if (!in_array($post_taxonomy, $taxonomies)) {
                    $taxonomies[] = $post_taxonomy;
                }
开发者ID:NiviJah,项目名称:acf-api-fields,代码行数:31,代码来源:relationship.php

示例13: render_field

    function render_field($field)
    {
        // echo "<pre>";
        // 	print_r($field);
        // echo "</pre>";
        $taxonomies = array();
        $taxonomies = acf_get_array($taxonomies);
        $taxonomies = acf_get_pretty_taxonomies($taxonomies);
        $all_taxonomies = acf_get_taxonomy_terms();
        $selected_taxonomies = array();
        $terms = array();
        $slug_name = !empty($field['choices']) ? $field['choices'] : array_keys(acf_get_pretty_taxonomies());
        foreach ($slug_name as $k1 => $v1) {
            $terms = array_merge($terms, get_terms($v1, array('hide_empty' => false)));
            foreach ($taxonomies as $k2 => $v2) {
                if ($v1 == $k2) {
                    $field['choices'][$k1] = $v2;
                }
            }
        }
        foreach ($field['choices'] as $k1 => $v1) {
            foreach ($all_taxonomies as $k2 => $v2) {
                if ($v1 == $k2) {
                    $selected_taxonomies[$v1] = $all_taxonomies[$k2];
                }
            }
        }
        $field['choices'] = $selected_taxonomies;
        // convert value to array
        // $field['value'] = acf_force_type_array($field['value']);
        // add empty value (allows '' to be selected)
        if (empty($field['value'])) {
            $field['value'][''] = '';
            $field['value']['cat'] = '';
        }
        // placeholder
        if (empty($field['placeholder'])) {
            $field['placeholder'] = __("Select", 'acf');
        }
        // vars
        $atts = array('id' => $field['id'], 'class' => $field['class'] . ' js-multi-taxonomy-select2', 'name' => $field['name'], 'data-ui' => $field['ui'], 'data-ajax' => $field['ajax'], 'data-multiple' => $field['multiple'], 'data-placeholder' => $field['placeholder'], 'data-allow_null' => $field['allow_null']);
        // hidden input
        if ($field['ui']) {
            acf_hidden_input(array('type' => 'hidden', 'id' => $field['id'], 'name' => $field['name'], 'value' => implode(',', $field['value'])));
        } elseif ($field['multiple']) {
            acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
        }
        // ui
        if ($field['ui']) {
            $atts['disabled'] = 'disabled';
            $atts['class'] .= ' acf-hidden';
        }
        // multiple
        if ($field['multiple']) {
            $atts['multiple'] = 'multiple';
            $atts['size'] = 5;
            $atts['name'] .= '[]';
        }
        // special atts
        foreach (array('readonly', 'disabled') as $k) {
            if (!empty($field[$k])) {
                $atts[$k] = $k;
            }
        }
        // vars
        $els = array();
        $choices = array();
        if ($field['data_type']) {
            // loop through values and add them as options
            if (!empty($field['choices'])) {
                foreach ($field['choices'] as $k => $v) {
                    if (is_array($v)) {
                        // optgroup
                        $els[] = array('type' => 'optgroup', 'label' => $k);
                        if (!empty($v)) {
                            foreach ($v as $k2 => $v2) {
                                if ($field['type_value']) {
                                    foreach ($terms as $key => $val) {
                                        if ($val->name == $v2) {
                                            $els[] = array('type' => 'option', 'value' => $val->term_id, 'label' => $v2, 'selected' => $slct = $val->term_id == $field['value'] ? "selected" : "");
                                        }
                                    }
                                } else {
                                    $els[] = array('type' => 'option', 'value' => $k2, 'label' => $v2, 'selected' => $slct = $k2 == $field['value'] ? "selected" : "");
                                }
                                $choices[] = $k2;
                            }
                        }
                        $els[] = array('type' => '/optgroup');
                    } else {
                        $els[] = array('type' => 'option', 'value' => $k, 'label' => $v, 'selected' => $slct = $k == $field['value'] ? "selected" : "");
                        $choices[] = $k;
                    }
                }
            }
            // null
            if ($field['allow_null']) {
                array_unshift($els, array('type' => 'option', 'value' => '', 'label' => '- ' . $field['placeholder'] . ' -'));
            }
            // html
//.........这里部分代码省略.........
开发者ID:marktimemedia,项目名称:acf-multi-taxonomy-chooser,代码行数:101,代码来源:acf-multi-taxonomy-chooser-v5.php

示例14: render_field

        function render_field($field)
        {
            // vars
            $sub_fields = $field['sub_fields'];
            $value = acf_get_array($field['value']);
            $show_order = true;
            $show_add = true;
            $show_remove = true;
            // bail early if no sub fields
            if (empty($sub_fields)) {
                return;
            }
            // div
            $div = array('class' => 'acf-repeater', 'data-min' => $field['min'], 'data-max' => $field['max']);
            // empty
            if (empty($value)) {
                $div['class'] .= ' -empty';
            }
            // If there are less values than min, populate the extra values
            if ($field['min']) {
                $value = array_pad($value, $field['min'], array());
            }
            // If there are more values than man, remove some values
            if ($field['max']) {
                $value = array_slice($value, 0, $field['max']);
                // if max 1 row, don't show order
                if ($field['max'] == 1) {
                    $show_order = false;
                }
                // if max == min, don't show add or remove buttons
                if ($field['max'] <= $field['min']) {
                    $show_remove = false;
                    $show_add = false;
                }
            }
            // setup values for row clone
            $value['acfcloneindex'] = array();
            // button label
            if ($field['button_label'] === '') {
                $field['button_label'] = __('Add Row', 'acf');
            }
            // field wrap
            $el = 'td';
            $before_fields = '';
            $after_fields = '';
            if ($field['layout'] == 'row') {
                $el = 'div';
                $before_fields = '<td class="acf-fields -left">';
                $after_fields = '</td>';
            } elseif ($field['layout'] == 'block') {
                $el = 'div';
                $before_fields = '<td class="acf-fields">';
                $after_fields = '</td>';
            }
            // layout
            $div['class'] .= ' -' . $field['layout'];
            // hidden input
            acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
            // collapsed
            if ($field['collapsed']) {
                // add target class
                foreach ($sub_fields as $i => $sub_field) {
                    // bail early if no match
                    if ($sub_field['key'] !== $field['collapsed']) {
                        continue;
                    }
                    // class
                    $sub_field['wrapper']['class'] .= ' -collapsed-target';
                    // update
                    $sub_fields[$i] = $sub_field;
                }
            }
            ?>
<div <?php 
            acf_esc_attr_e($div);
            ?>
>
<table class="acf-table">
	
	<?php 
            if ($field['layout'] == 'table') {
                ?>
		<thead>
			<tr>
				<?php 
                if ($show_order) {
                    ?>
					<th class="acf-row-handle"></th>
				<?php 
                }
                ?>
				
				<?php 
                foreach ($sub_fields as $sub_field) {
                    // prepare field (allow sub fields to be removed)
                    $sub_field = acf_prepare_field($sub_field);
                    // bail ealry if no field
                    if (!$sub_field) {
                        continue;
                    }
//.........这里部分代码省略.........
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:101,代码来源:repeater.php

示例15: get_ajax_query

 function get_ajax_query($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'field_key' => '', 'paged' => 1));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         return false;
     }
     // vars
     $results = array();
     $args = array();
     $s = false;
     $is_search = false;
     // paged
     $args['posts_per_page'] = 20;
     $args['paged'] = $options['paged'];
     // search
     if ($options['s'] !== '') {
         // strip slashes (search may be integer)
         $s = wp_unslash(strval($options['s']));
         // update vars
         $args['s'] = $s;
         $is_search = true;
     }
     // post_type
     if (!empty($field['post_type'])) {
         $args['post_type'] = acf_get_array($field['post_type']);
     } else {
         $args['post_type'] = acf_get_post_types();
     }
     // taxonomy
     if (!empty($field['taxonomy'])) {
         // vars
         $terms = acf_decode_taxonomy_terms($field['taxonomy']);
         // append to $args
         $args['tax_query'] = array();
         // now create the tax queries
         foreach ($terms as $k => $v) {
             $args['tax_query'][] = array('taxonomy' => $k, 'field' => 'slug', 'terms' => $v);
         }
     }
     // filters
     $args = apply_filters('acf/fields/post_object/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/post_object/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/post_object/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get posts grouped by post type
     $groups = acf_get_grouped_posts($args);
     // bail early if no posts
     if (empty($groups)) {
         return false;
     }
     // loop
     foreach (array_keys($groups) as $group_title) {
         // vars
         $posts = acf_extract_var($groups, $group_title);
         // data
         $data = array('text' => $group_title, 'children' => array());
         // convert post objects to post titles
         foreach (array_keys($posts) as $post_id) {
             $posts[$post_id] = $this->get_post_title($posts[$post_id], $field, $options['post_id'], $is_search);
         }
         // order posts by search
         if ($is_search && empty($args['orderby'])) {
             $posts = acf_order_by_search($posts, $args['s']);
         }
         // append to $data
         foreach (array_keys($posts) as $post_id) {
             $data['children'][] = $this->get_post_result($post_id, $posts[$post_id]);
         }
         // append to $results
         $results[] = $data;
     }
     // optgroup or single
     if (count($args['post_type']) == 1) {
         $results = $results[0]['children'];
     }
     // vars
     $response = array('results' => $results, 'limit' => $args['posts_per_page']);
     // return
     return $response;
 }
开发者ID:Garth619,项目名称:Femi9,代码行数:82,代码来源:post_object.php


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