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


PHP acf_force_type_array函数代码示例

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


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

示例1: clean_post_value

 function clean_post_value($value)
 {
     // validate
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_force_type_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:royjanik,项目名称:acf-2way-pr,代码行数:20,代码来源:acf-2way-pr-v5.php

示例2: render_field

 function render_field($field)
 {
     // force value to array
     $field['value'] = acf_force_type_array($field['value']);
     // convert values to int
     $field['value'] = array_map('intval', $field['value']);
     // get taxonomy
     $taxonomy = get_taxonomy($field['taxonomy']);
     // Change Field into a select
     $field['type'] = 'select';
     $field['ui'] = 1;
     $field['ajax'] = 1;
     $field['choices'] = array();
     // value
     if (!empty($field['value'])) {
         // get terms
     }
     // render select
     acf_render_field($field);
     var_dump($field);
 }
开发者ID:quangnpd,项目名称:jobshop_web,代码行数:21,代码来源:taxonomy-object.php

示例3: render_field

 function render_field($field)
 {
     // decode value (convert to array)
     $field['value'] = acf_force_type_array($field['value']);
     // hiden input
     acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
     // vars
     $i = 0;
     // class
     $field['class'] .= ' acf-checkbox-list';
     $field['class'] .= $field['layout'] == 'horizontal' ? ' acf-hl' : ' acf-bl';
     // e
     $e = '<ul ' . acf_esc_attr(array('class' => $field['class'])) . '>';
     // 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);
             if (in_array($value, $field['value'])) {
                 $atts['checked'] = 'checked';
             }
             if (isset($field['disabled']) && in_array($value, $field['disabled'])) {
                 $atts['disabled'] = 'true';
             }
             // 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;
             }
             $e .= '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>';
         }
     }
     $e .= '</ul>';
     // return
     echo $e;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:39,代码来源:checkbox.php

示例4: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_force_type_array($value);
     // convert values to int
     $value = array_map('intval', $value);
     // load users
     foreach (array_keys($value) as $i) {
         // vars
         $user_id = $value[$i];
         $user_data = get_userdata($user_id);
         //cope with deleted users by @adampope
         if (!is_object($user_data)) {
             unset($value[$i]);
             continue;
         }
         // append to array
         $value[$i] = array();
         $value[$i]['ID'] = $user_id;
         $value[$i]['user_firstname'] = $user_data->user_firstname;
         $value[$i]['user_lastname'] = $user_data->user_lastname;
         $value[$i]['nickname'] = $user_data->nickname;
         $value[$i]['user_nicename'] = $user_data->user_nicename;
         $value[$i]['display_name'] = $user_data->display_name;
         $value[$i]['user_email'] = $user_data->user_email;
         $value[$i]['user_url'] = $user_data->user_url;
         $value[$i]['user_registered'] = $user_data->user_registered;
         $value[$i]['user_description'] = $user_data->user_description;
         $value[$i]['user_avatar'] = get_avatar($user_id);
     }
     // convert back from array if neccessary
     if (!$field['multiple']) {
         $value = array_shift($value);
     }
     // return value
     return $value;
 }
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:41,代码来源:user.php

示例5: render_field

        function render_field($field)
        {
            // force value to array
            $field['value'] = acf_force_type_array($field['value']);
            // convert values to int
            $field['value'] = array_map('intval', $field['value']);
            // vars
            $div = array('class' => 'acf-taxonomy-field acf-soh', 'data-load_save' => $field['load_save_terms'], 'data-type' => $field['field_type'], 'data-taxonomy' => $field['taxonomy']);
            // get taxonomy
            $taxonomy = get_taxonomy($field['taxonomy']);
            ?>
<div <?php 
            acf_esc_attr_e($div);
            ?>
>
	<?php 
            if ($field['add_term'] && current_user_can($taxonomy->cap->manage_terms)) {
                ?>
	<a href="#" class="acf-js-tooltip acf-icon small acf-soh-target" data-name="add" title="<?php 
                echo sprintf(__('Add new %s ', 'acf'), $taxonomy->labels->singular_name);
                ?>
">
		<i class="acf-sprite-add"></i>
	</a>
	<?php 
            }
            if ($field['field_type'] == 'select') {
                $field['multiple'] = 0;
                $this->render_field_select($field);
            } elseif ($field['field_type'] == 'multi_select') {
                $field['multiple'] = 1;
                $this->render_field_select($field);
            } elseif ($field['field_type'] == 'radio') {
                $this->render_field_checkbox($field);
            } elseif ($field['field_type'] == 'checkbox') {
                $this->render_field_checkbox($field);
            }
            ?>
</div><?php 
        }
开发者ID:shelbyneilsmith,项目名称:wptools,代码行数:40,代码来源:taxonomy.php

示例6: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_force_type_array($value);
     // convert values to int
     $value = array_map('intval', $value);
     // load posts if needed
     if ($field['return_format'] == 'object') {
         // get posts
         $value = $this->get_posts($value);
     }
     // convert back from array if neccessary
     if (!$field['multiple']) {
         $value = array_shift($value);
     }
     // return value
     return $value;
 }
开发者ID:adnandot,项目名称:intenseburn,代码行数:22,代码来源:post_object.php

示例7: get_posts

 function get_posts($value)
 {
     // force value to array
     $value = acf_force_type_array($value);
     // get selected post ID's
     $post__in = array();
     foreach (array_keys($value) as $k) {
         if (is_numeric($value[$k])) {
             // convert to int
             $value[$k] = intval($value[$k]);
             // append to $post__in
             $post__in[] = $value[$k];
         }
     }
     // bail early if no posts
     if (empty($post__in)) {
         return $value;
     }
     // get posts
     $posts = acf_get_posts(array('post__in' => $post__in));
     // override value with post
     $return = array();
     // append to $return
     foreach ($value as $k => $v) {
         if (is_numeric($v)) {
             // find matching $post
             foreach ($posts as $post) {
                 if ($post->ID == $v) {
                     $return[] = $post;
                     break;
                 }
             }
         } else {
             $return[] = $v;
         }
     }
     // return
     return $return;
 }
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:39,代码来源:page_link.php

示例8: get_valid_relationship_field

 function get_valid_relationship_field($field)
 {
     // force array
     $field['post_type'] = acf_force_type_array($field['post_type']);
     $field['taxonomy'] = acf_force_type_array($field['taxonomy']);
     // remove 'all' from post_type
     if (acf_in_array('all', $field['post_type'])) {
         $field['post_type'] = array();
     }
     // remove 'all' from taxonomy
     if (acf_in_array('all', $field['taxonomy'])) {
         $field['taxonomy'] = array();
     }
     // save_format is now return_format
     if (!empty($field['result_elements'])) {
         $field['elements'] = acf_extract_var($field, 'result_elements');
     }
     // return
     return $field;
 }
开发者ID:bmavus,项目名称:wp-theme-blank,代码行数:20,代码来源:compatibility.php

示例9: acf_get_posts

function acf_get_posts($args)
{
    // vars
    $r = array();
    // defaults
    $args = acf_parse_args($args, array('posts_per_page' => -1, 'post_type' => 'post', 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false));
    // find array of post_type
    $post_types = acf_force_type_array($args['post_type']);
    // attachment doesn't work if it is the only item in an array
    if (count($post_types) == 1) {
        $args['post_type'] = current($post_types);
    }
    // get posts
    $posts = get_posts($args);
    // loop
    foreach ($post_types as $post_type) {
        // vars
        $this_posts = array();
        $this_group = array();
        // populate $this_posts
        foreach (array_keys($posts) as $key) {
            if ($posts[$key]->post_type == $post_type) {
                $this_posts[] = acf_extract_var($posts, $key);
            }
        }
        // bail early if no posts for this post type
        if (empty($this_posts)) {
            continue;
        }
        // sort into hierachial order!
        if (is_post_type_hierarchical($post_type)) {
            // this will fail if a search has taken place because parents wont exist
            if (empty($args['s'])) {
                $this_posts = get_page_children(0, $this_posts);
            }
        }
        // populate $this_posts
        foreach (array_keys($this_posts) as $key) {
            // extract post
            $post = acf_extract_var($this_posts, $key);
            // add to group
            $this_group[$post->ID] = $post;
        }
        // group by post type
        $post_type_object = get_post_type_object($post_type);
        $post_type_name = $post_type_object->labels->name;
        $r[$post_type_name] = $this_group;
    }
    // return
    return $r;
}
开发者ID:pellio11,项目名称:ns-select-project,代码行数:51,代码来源:api-helpers.php

示例10: acf_get_posts

function acf_get_posts($args)
{
    // vars
    $r = array();
    // defaults
    $args = acf_parse_args($args, array('posts_per_page' => -1, 'paged' => 0, 'post_type' => 'post', 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false));
    // find array of post_type
    $post_types = acf_force_type_array($args['post_type']);
    $post_types_labels = acf_get_pretty_post_types($post_types);
    // attachment doesn't work if it is the only item in an array
    if (count($post_types) == 1) {
        $args['post_type'] = current($post_types);
    }
    // add filter to orderby post type
    add_filter('posts_orderby', '_acf_orderby_post_type', 10, 2);
    // get posts
    $posts = get_posts($args);
    // loop
    foreach ($post_types as $post_type) {
        // vars
        $this_posts = array();
        $this_group = array();
        // populate $this_posts
        foreach (array_keys($posts) as $key) {
            if ($posts[$key]->post_type == $post_type) {
                $this_posts[] = acf_extract_var($posts, $key);
            }
        }
        // bail early if no posts for this post type
        if (empty($this_posts)) {
            continue;
        }
        // sort into hierachial order!
        // this will fail if a search has taken place because parents wont exist
        if (is_post_type_hierarchical($post_type) && empty($args['s'])) {
            // vars
            $match_id = $this_posts[0]->ID;
            $offset = 0;
            $length = count($this_posts);
            // reset $this_posts
            $this_posts = array();
            // get all posts
            $all_args = array_merge($args, array('posts_per_page' => -1, 'paged' => 0, 'post_type' => $post_type));
            $all_posts = get_posts($all_args);
            // loop over posts and find $i
            foreach ($all_posts as $offset => $p) {
                if ($p->ID == $match_id) {
                    break;
                }
            }
            // order posts
            $all_posts = get_page_children(0, $all_posts);
            for ($i = $offset; $i < $offset + $length; $i++) {
                $this_posts[] = acf_extract_var($all_posts, $i);
            }
        }
        // populate $this_posts
        foreach (array_keys($this_posts) as $key) {
            // extract post
            $post = acf_extract_var($this_posts, $key);
            // add to group
            $this_group[$post->ID] = $post;
        }
        // group by post type
        $post_type_name = $post_types_labels[$post_type];
        $r[$post_type_name] = $this_group;
    }
    // return
    return $r;
}
开发者ID:mariussunde,项目名称:Sn-hetta-Designmanual-WP-Theme,代码行数:70,代码来源:api-helpers.php

示例11: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_force_type_array($value);
     // convert values to int
     $value = array_map('intval', $value);
     // load posts in 1 query to save multiple DB calls from following code
     $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'attachment', 'post_status' => 'any', 'post__in' => $value, 'orderby' => 'post__in'));
     foreach ($value as $k => $v) {
         // get post
         $post = get_post($v);
         // create $attachment
         $a = array('ID' => $post->ID, 'id' => $post->ID, 'alt' => get_post_meta($post->ID, '_wp_attachment_image_alt', true), 'title' => $post->post_title, 'caption' => $post->post_excerpt, 'description' => $post->post_content, 'mime_type' => $post->post_mime_type, 'type' => 'file', 'url' => '');
         // image
         if (strpos($a['mime_type'], 'image') !== false) {
             // type
             $a['type'] = 'image';
             // url
             $src = wp_get_attachment_image_src($a['ID'], 'full');
             $a['url'] = $src[0];
             $a['width'] = $src[1];
             $a['height'] = $src[2];
             // find all image sizes
             $sizes = get_intermediate_image_sizes();
             // sizes
             if (!empty($sizes)) {
                 $a['sizes'] = array();
                 foreach ($sizes as $size) {
                     // url
                     $src = wp_get_attachment_image_src($a['ID'], $size);
                     // add src
                     $a['sizes'][$size] = $src[0];
                     $a['sizes'][$size . '-width'] = $src[1];
                     $a['sizes'][$size . '-height'] = $src[2];
                 }
                 // foreach
             }
             // if
         } else {
             // is file
             $src = wp_get_attachment_url($a['ID']);
             $a['url'] = $src;
         }
         $value[$k] = $a;
     }
     // foreach
     // return
     return $value;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:53,代码来源:gallery.php

示例12: format_value_for_api

 function format_value_for_api($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_force_type_array($value);
     // convert values to int
     $value = array_map('intval', $value);
     // load posts if needed
     if ($field['return_format'] == 'object') {
         // get posts
         $value = $this->get_terms($value, $field["taxonomy"]);
     }
     // convert back from array if neccessary
     if ($field['field_type'] == 'select' || $field['field_type'] == 'radio') {
         $value = array_shift($value);
     }
     // return
     return $value;
 }
开发者ID:Didox,项目名称:beminfinito,代码行数:22,代码来源:taxonomy.php

示例13: get_posts

 function get_posts($value)
 {
     // force value to array
     $value = acf_force_type_array($value);
     // get selected post ID's
     $post_ids = array();
     foreach ($value as $v) {
         if (is_numeric($v)) {
             $post_ids[] = intval($v);
         }
     }
     // load posts in 1 query to save multiple DB calls from following code
     if (count($post_ids) > 1) {
         get_posts(array('posts_per_page' => -1, 'post_type' => acf_get_post_types(), 'post_status' => 'any', 'post__in' => $post_ids));
     }
     // vars
     $posts = array();
     // update value to include $post
     foreach ($value as $v) {
         if (is_numeric($v)) {
             if ($post = get_post($v)) {
                 $posts[] = $post;
             }
         } else {
             $posts[] = $v;
         }
     }
     // return
     return $posts;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:30,代码来源:page_link.php

示例14: 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_force_type_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:sdh100shaun,项目名称:pantheon,代码行数:26,代码来源:api-helpers.php

示例15: 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_force_type_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:kochira,项目名称:competstrat,代码行数:46,代码来源:flexible-content.php


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