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


PHP acf_get_field函数代码示例

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


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

示例1: get_choices

 function get_choices($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'field_key' => ''));
     // vars
     $r = array();
     $args = array('hide_empty' => false);
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         return false;
     }
     // search
     if ($options['s']) {
         $args['search'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get terms
     $terms = get_terms($field['taxonomy'], $args);
     // sort into hierachial order!
     if (is_taxonomy_hierarchical($field['taxonomy'])) {
         // get parent
         $parent = acf_maybe_get($args, 'parent', 0);
         $parent = acf_maybe_get($args, 'child_of', $parent);
         // this will fail if a search has taken place because parents wont exist
         if (empty($args['search'])) {
             $terms = _get_term_children($parent, $terms, $field['taxonomy']);
         }
     }
     /// append to r
     foreach ($terms as $term) {
         // add to json
         $r[] = array('id' => $term->term_id, 'text' => $this->get_term_title($term, $field, $options['post_id']));
     }
     // return
     return $r;
 }
开发者ID:brycefrees,项目名称:nddLive,代码行数:40,代码来源:taxonomy.php

示例2: ajax_layout_title

 function ajax_layout_title()
 {
     // options
     $options = acf_parse_args($_POST, array('post_id' => 0, 'i' => 0, 'field_key' => '', 'nonce' => '', 'layout' => '', 'acf' => array()));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // vars
     $layout = false;
     foreach ($field['layouts'] as $k => $layout) {
         if ($layout['name'] === $options['layout']) {
             break;
         }
     }
     // bail ealry if no layout
     if (!$layout) {
         die;
     }
     // value
     // this flexible content field may be a sub field so it is important to
     // loop though all $_POST data to find thi's field's row value
     $value = $options['acf'];
     while (is_array($value)) {
         // get first key
         $k = key($value);
         // update value
         $value = array_pop($value[$k]);
         // stop looking if we have found the correct field's value
         if ($k === $options['field_key']) {
             break;
         }
     }
     // title
     $title = $this->get_layout_title($field, $layout, $options['i'], $value);
     // echo
     echo $title;
     die;
 }
开发者ID:cimocimocimo,项目名称:staydrysystems.com,代码行数:40,代码来源:flexible-content.php

示例3: ajax_query

 function ajax_query()
 {
     // options
     $options = acf_parse_args($_POST, array('post_id' => 0, 's' => '', 'field_key' => '', 'nonce' => ''));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // vars
     $r = array();
     $s = false;
     // search
     if ($options['s'] !== '') {
         // search may be integer
         $s = strval($options['s']);
         // strip slashes
         $s = wp_unslash($s);
     }
     // loop through choices
     if (!empty($field['choices'])) {
         foreach ($field['choices'] as $k => $v) {
             // if searching, but doesn't exist
             if ($s !== false && stripos($v, $s) === false) {
                 continue;
             }
             // append
             $r[] = array('id' => $k, 'text' => strval($v));
         }
     }
     // return JSON
     echo json_encode($r);
     die;
 }
开发者ID:SayenkoDesign,项目名称:bushcooking.com,代码行数:34,代码来源:select.php

示例4: ajax_query

 function ajax_query()
 {
     // options
     $options = acf_parse_args($_GET, array('post_id' => 0, 's' => '', 'field_key' => '', 'nonce' => ''));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // vars
     $r = array();
     // strip slashes
     $options['s'] = wp_unslash($options['s']);
     if (!empty($field['choices'])) {
         foreach ($field['choices'] as $k => $v) {
             // search
             if ($options['s'] && stripos($v, $options['s']) === false) {
                 continue;
             }
             // append
             $r[] = array('id' => $k, 'text' => strval($v));
         }
     }
     // return JSON
     echo json_encode($r);
     die;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:27,代码来源:select.php

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

示例6: ajax_query

 function ajax_query()
 {
     // options
     $options = acf_parse_args($_GET, array('post_id' => 0, 's' => '', 'field_key' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         die;
     }
     // vars
     $r = array();
     $args = array('hide_empty' => false);
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // search
     if ($options['s']) {
         $args['search'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get terms
     $terms = get_terms($field['taxonomy'], $args);
     // sort into hierachial order!
     if (is_taxonomy_hierarchical($field['taxonomy'])) {
         // this will fail if a search has taken place because parents wont exist
         if (empty($args['search'])) {
             $terms = _get_term_children(0, $terms, $field['taxonomy']);
         }
     }
     /// append to r
     foreach ($terms as $term) {
         // add to json
         $r[] = array('id' => $term->term_id, 'text' => $this->get_term_title($term, $field, $options['post_id']));
     }
     // return JSON
     echo json_encode($r);
     die;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:42,代码来源:taxonomy.php

示例7: ajax_get_attachment

 function ajax_get_attachment()
 {
     // options
     $options = acf_parse_args($_POST, array('post_id' => 0, 'id' => 0, 'field_key' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         die;
     }
     if (empty($options['id'])) {
         die;
     }
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // render
     $this->render_attachment($options['id'], $field);
     die;
 }
开发者ID:TMBR,项目名称:johnjohn,代码行数:20,代码来源:gallery.php

示例8: get_choices

 function get_choices($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'post_type' => '', 'taxonomy' => '', 'lang' => false, 'field_key' => '', 'paged' => 1));
     // vars
     $r = array();
     $args = array();
     // paged
     $args['posts_per_page'] = 20;
     $args['paged'] = $options['paged'];
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         return false;
     }
     // WPML
     if ($options['lang']) {
         global $sitepress;
         if (!empty($sitepress)) {
             $sitepress->switch_lang($options['lang']);
         }
     }
     // update $args
     if (!empty($options['post_type'])) {
         $args['post_type'] = acf_force_type_array($options['post_type']);
     } elseif (!empty($field['post_type'])) {
         $args['post_type'] = acf_force_type_array($field['post_type']);
     } else {
         $args['post_type'] = acf_get_post_types();
     }
     // update taxonomy
     $taxonomies = array();
     if (!empty($options['taxonomy'])) {
         $term = acf_decode_taxonomy_term($options['taxonomy']);
         // append to $args
         $args['tax_query'] = array(array('taxonomy' => $term['taxonomy'], 'field' => 'slug', 'terms' => $term['term']));
     } elseif (!empty($field['taxonomy'])) {
         $taxonomies = acf_decode_taxonomy_terms($field['taxonomy']);
         // append to $args
         $args['tax_query'] = array();
         // now create the tax queries
         foreach ($taxonomies as $taxonomy => $terms) {
             $args['tax_query'][] = array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $terms);
         }
     }
     // search
     if ($options['s']) {
         $args['s'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/relationship/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/relationship/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get posts grouped by post type
     $groups = acf_get_grouped_posts($args);
     if (!empty($groups)) {
         foreach (array_keys($groups) as $group_title) {
             // vars
             $posts = acf_extract_var($groups, $group_title);
             $titles = array();
             // data
             $data = array('text' => $group_title, 'children' => array());
             foreach (array_keys($posts) as $post_id) {
                 // override data
                 $posts[$post_id] = $this->get_post_title($posts[$post_id], $field, $options['post_id']);
             }
             // order by search
             if (!empty($args['s'])) {
                 $posts = acf_order_by_search($posts, $args['s']);
             }
             // append to $data
             foreach (array_keys($posts) as $post_id) {
                 $data['children'][] = array('id' => $post_id, 'text' => $posts[$post_id]);
             }
             // append to $r
             $r[] = $data;
         }
         // optgroup or single
         $post_types = acf_force_type_array($args['post_type']);
         // add as optgroup or results
         if (count($post_types) == 1) {
             $r = $r[0]['children'];
         }
     }
     // return
     return $r;
 }
开发者ID:quangnpd,项目名称:jobshop_web,代码行数:87,代码来源:relationship.php

示例9: get_clone_setting_choice

 function get_clone_setting_choice($selector = '')
 {
     // bail early no selector
     if (!$selector) {
         return '';
     }
     // ajax_fields
     if (isset($_POST['fields'][$selector])) {
         return $this->get_clone_setting_field_choice($_POST['fields'][$selector]);
     }
     // field
     if (acf_is_field_key($selector)) {
         return $this->get_clone_setting_field_choice(acf_get_field($selector));
     }
     // group
     if (acf_is_field_group_key($selector)) {
         return $this->get_clone_setting_group_choice(acf_get_field_group($selector));
     }
     // return
     return $selector;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:21,代码来源:clone.php

示例10: get_field_objects

function get_field_objects($post_id = false, $format_value = true, $load_value = true)
{
    // global
    global $wpdb;
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // vars
    $meta = array();
    $fields = array();
    // get field_names
    if (is_numeric($post_id)) {
        $meta = get_post_meta($post_id);
    } elseif (strpos($post_id, 'user_') !== false) {
        $user_id = (int) str_replace('user_', '', $post_id);
        $meta = get_user_meta($user_id);
    } elseif (strpos($post_id, 'comment_') !== false) {
        $comment_id = (int) str_replace('comment_', '', $post_id);
        $meta = get_comment_meta($comment_id);
    } else {
        $rows = $wpdb->get_results($wpdb->prepare("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $post_id . '_%', '_' . $post_id . '_%'), ARRAY_A);
        if (!empty($rows)) {
            foreach ($rows as $row) {
                $meta[$row['option_name']][] = $row['option_value'];
            }
        }
    }
    // bail early if no meta
    if (empty($meta)) {
        return false;
    }
    // populate vars
    foreach ($meta as $k => $v) {
        // Hopefuly improve efficiency: bail early if $k does start with an '_'
        if ($k[0] === '_') {
            continue;
        }
        // does a field key exist for this value?
        if (!array_key_exists("_{$k}", $meta)) {
            continue;
        }
        // get field
        $field_key = $meta["_{$k}"][0];
        $field = acf_get_field($field_key);
        // bail early if not a parent field
        if (!$field || acf_is_sub_field($field)) {
            continue;
        }
        // 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);
        }
        // append to $value
        $fields[$field['name']] = $field;
    }
    // no value
    if (empty($fields)) {
        return false;
    }
    // return
    return $fields;
}
开发者ID:de190909,项目名称:WPTest,代码行数:66,代码来源:api-template.php

示例11: get_choices

 function get_choices($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'lang' => false, 'field_key' => '', 'paged' => 1));
     // vars
     $r = array();
     $args = array();
     // paged
     $args['posts_per_page'] = 20;
     $args['paged'] = $options['paged'];
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         return false;
     }
     // update $args
     if (!empty($field['post_type'])) {
         $args['post_type'] = acf_get_array($field['post_type']);
     } else {
         $args['post_type'] = acf_get_post_types();
     }
     // create tax queries
     if (!empty($field['taxonomy'])) {
         // append to $args
         $args['tax_query'] = array();
         // decode terms
         $taxonomies = acf_decode_taxonomy_terms($field['taxonomy']);
         // now create the tax queries
         foreach ($taxonomies as $taxonomy => $terms) {
             $args['tax_query'][] = array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $terms);
         }
     }
     // search
     if ($options['s']) {
         $args['s'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/page_link/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/page_link/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // add archives to $r
     if ($args['paged'] == 1) {
         $archives = array();
         $archives[] = array('id' => home_url(), 'text' => home_url());
         foreach ($args['post_type'] as $post_type) {
             $archive_link = get_post_type_archive_link($post_type);
             if ($archive_link) {
                 $archives[] = array('id' => $archive_link, 'text' => $archive_link);
             }
         }
         // search
         if (!empty($args['s'])) {
             foreach (array_keys($archives) as $i) {
                 if (strpos($archives[$i]['text'], $args['s']) === false) {
                     unset($archives[$i]);
                 }
             }
             $archives = array_values($archives);
         }
         if (!empty($archives)) {
             $r[] = array('text' => __('Archives', 'acf'), 'children' => $archives);
         }
     }
     // get posts grouped by post type
     $groups = acf_get_grouped_posts($args);
     if (!empty($groups)) {
         foreach (array_keys($groups) as $group_title) {
             // vars
             $posts = acf_extract_var($groups, $group_title);
             $titles = array();
             // data
             $data = array('text' => $group_title, 'children' => array());
             foreach (array_keys($posts) as $post_id) {
                 // override data
                 $posts[$post_id] = $this->get_post_title($posts[$post_id], $field, $options['post_id']);
             }
             // order by search
             if (!empty($args['s'])) {
                 $posts = acf_order_by_search($posts, $args['s']);
             }
             // append to $data
             foreach (array_keys($posts) as $post_id) {
                 $data['children'][] = array('id' => $post_id, 'text' => $posts[$post_id]);
             }
             // append to $r
             $r[] = $data;
         }
     }
     // return
     return $r;
 }
开发者ID:de190909,项目名称:WPTest,代码行数:91,代码来源:page_link.php

示例12: ajax_query

 function ajax_query()
 {
     // validate
     if (!acf_verify_ajax()) {
         die;
     }
     // defaults
     $options = acf_parse_args($_POST, array('post_id' => 0, 's' => '', 'field_key' => '', 'paged' => 1));
     // 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;
     }
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // update $args
     if (!empty($field['post_type'])) {
         $args['post_type'] = acf_get_array($field['post_type']);
     } else {
         $args['post_type'] = acf_get_post_types();
     }
     // create tax queries
     if (!empty($field['taxonomy'])) {
         // append to $args
         $args['tax_query'] = array();
         // decode terms
         $taxonomies = acf_decode_taxonomy_terms($field['taxonomy']);
         // now create the tax queries
         foreach ($taxonomies as $taxonomy => $terms) {
             $args['tax_query'][] = array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $terms);
         }
     }
     // filters
     $args = apply_filters('acf/fields/page_link/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/page_link/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // add archives to $results
     if ($field['allow_archives'] && $args['paged'] == 1) {
         $archives = array();
         $archives[] = array('id' => home_url(), 'text' => home_url());
         foreach ($args['post_type'] as $post_type) {
             // vars
             $archive_link = get_post_type_archive_link($post_type);
             // bail ealry if no link
             if (!$archive_link) {
                 continue;
             }
             // bail early if no search match
             if ($is_search && stripos($archive_link, $s) === false) {
                 continue;
             }
             // append
             $archives[] = array('id' => $archive_link, 'text' => $archive_link);
         }
         // append
         $results[] = array('text' => __('Archives', 'acf'), 'children' => $archives);
     }
     // get posts grouped by post type
     $groups = acf_get_grouped_posts($args);
     // loop
     if (!empty($groups)) {
         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;
         }
     }
     // return
     acf_send_ajax_results(array('results' => $results, 'limit' => $args['posts_per_page']));
 }
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:99,代码来源:page_link.php

示例13: update_value

 function update_value($value, $post_id, $field)
 {
     // save_other_choice
     if ($field['save_other_choice']) {
         // value isn't in choices yet
         if (!isset($field['choices'][$value])) {
             // get ID if local
             if (!$field['ID']) {
                 $field = acf_get_field($field['key'], true);
             }
             // bail early if no ID
             if (!$field['ID']) {
                 return $value;
             }
             // update $field
             $field['choices'][$value] = $value;
             // save
             acf_update_field($field);
         }
     }
     // return
     return $value;
 }
开发者ID:de190909,项目名称:WPTest,代码行数:23,代码来源:radio.php

示例14: remove_field

 function remove_field($key)
 {
     // get field
     $field = acf_get_field($key);
     // remove parent reference
     $this->remove_parent_reference($field['parent'], $field['key']);
     // remove field
     unset($this->fields[$key]);
     // remove children
     if (acf_have_local_fields($key)) {
         acf_remove_local_fields($key);
     }
 }
开发者ID:slavic18,项目名称:cats,代码行数:13,代码来源:local.php

示例15: update_value

 function update_value($value, $post_id, $field)
 {
     // bail early if is empty
     if (empty($value)) {
         return $value;
     }
     // select -> update_value()
     $value = acf_get_field_type('select')->update_value($value, $post_id, $field);
     // save_other_choice
     if ($field['save_custom']) {
         // get raw $field (may have been changed via repeater field)
         // if field is local, it won't have an ID
         $selector = $field['ID'] ? $field['ID'] : $field['key'];
         $field = acf_get_field($selector, true);
         // bail early if no ID (JSON only)
         if (!$field['ID']) {
             return $value;
         }
         // loop
         foreach ($value as $v) {
             // ignore if already eixsts
             if (isset($field['choices'][$v])) {
                 continue;
             }
             // append
             $field['choices'][$v] = $v;
         }
         // save
         acf_update_field($field);
     }
     // return
     return $value;
 }
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:33,代码来源:checkbox.php


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