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


PHP acf_decode_taxonomy_terms函数代码示例

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


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

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

示例2: render_field

        function render_field($field)
        {
            // vars
            $values = array();
            $atts = array('id' => $field['id'], 'class' => "acf-relationship {$field['class']}", 'data-min' => $field['min'], 'data-max' => $field['max'], 'data-s' => '', 'data-post_type' => '', 'data-taxonomy' => '', 'data-paged' => 1);
            // Lang
            if (defined('ICL_LANGUAGE_CODE')) {
                $atts['data-lang'] = ICL_LANGUAGE_CODE;
            }
            // data types
            $field['post_type'] = acf_force_type_array($field['post_type']);
            $field['taxonomy'] = acf_force_type_array($field['taxonomy']);
            // post_types
            $post_types = array();
            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);
            // taxonomies
            $taxonomies = array();
            if (!empty($field['taxonomy'])) {
                // get the field's terms
                $term_groups = acf_force_type_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;
                        }
                    }
                }
            } else {
                $taxonomies = acf_get_taxonomies();
            }
            // terms
            $term_groups = acf_get_taxonomy_terms($taxonomies);
            // update $term_groups with specific terms
            if (!empty($field['taxonomy'])) {
                foreach (array_keys($term_groups) as $taxonomy) {
                    foreach (array_keys($term_groups[$taxonomy]) as $term) {
                        if (!in_array($term, $field['taxonomy'])) {
                            unset($term_groups[$taxonomy][$term]);
                        }
                    }
                }
            }
            // width for select filters
            $width = array('search' => 0, 'post_type' => 0, 'taxonomy' => 0);
            if (!empty($field['filters'])) {
                $width = array('search' => 50, 'post_type' => 25, 'taxonomy' => 25);
                foreach (array_keys($width) as $k) {
                    if (!in_array($k, $field['filters'])) {
                        $width[$k] = 0;
                    }
                }
                // search
                if ($width['search'] == 0) {
                    $width['post_type'] = $width['post_type'] == 0 ? 0 : 50;
                    $width['taxonomy'] = $width['taxonomy'] == 0 ? 0 : 50;
                }
                // post_type
                if ($width['post_type'] == 0) {
                    $width['taxonomy'] = $width['taxonomy'] == 0 ? 0 : 50;
                }
                // taxonomy
                if ($width['taxonomy'] == 0) {
                    $width['post_type'] = $width['post_type'] == 0 ? 0 : 50;
                }
                // search
                if ($width['post_type'] == 0 && $width['taxonomy'] == 0) {
                    $width['search'] = $width['search'] == 0 ? 0 : 100;
                }
            }
            ?>
<div <?php 
            acf_esc_attr_e($atts);
            ?>
>
	
	<div class="acf-hidden">
		<input type="hidden" name="<?php 
            echo $field['name'];
            ?>
" value="" />
	</div>
	
	<?php 
            if ($width['search'] > 0 || $width['post_type'] > 0 || $width['taxonomy'] > 0) {
                ?>
//.........这里部分代码省略.........
开发者ID:quangnpd,项目名称:jobshop_web,代码行数:101,代码来源:relationship.php

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

示例4: 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;
     }
     // WPML
     if ($options['lang']) {
         global $sitepress;
         if (!empty($sitepress)) {
             $sitepress->switch_lang($options['lang']);
         }
     }
     // update $args
     if (!empty($field['post_type'])) {
         $args['post_type'] = acf_force_type_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/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_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:adnandot,项目名称:intenseburn,代码行数:81,代码来源:post_object.php

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

示例6: ajax_query

 function ajax_query()
 {
     // options
     $options = acf_parse_args($_GET, array('post_id' => 0, 's' => '', 'lang' => false, 'field_key' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         die;
     }
     // vars
     $r = array();
     $args = array();
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // WPML
     if ($options['lang']) {
         global $sitepress;
         $sitepress->switch_lang($options['lang']);
     }
     // update $args
     if (!empty($field['post_type'])) {
         $args['post_type'] = acf_force_type_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
     $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);
         }
     }
     $r[] = array('text' => __('Archives', 'acf'), 'children' => $archives);
     // get posts grouped by post type
     $groups = acf_get_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 JSON
     echo json_encode($r);
     die;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:85,代码来源:page_link.php

示例7: acf_get_post_types

    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


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