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


PHP acf_decode_taxonomy_term函数代码示例

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


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

示例1: acf_location_rule_match_category_ancestor

function acf_location_rule_match_category_ancestor($match, $rule, $options)
{
    // most of this copied directly from acf post category rule
    $terms = $options['post_taxonomy'];
    $data = acf_decode_taxonomy_term($rule['value']);
    $term = get_term_by('slug', $data['term'], $data['taxonomy']);
    if (!$term && is_numeric($data['term'])) {
        $term = get_term_by('id', $data['term'], $data['taxonomy']);
    }
    // this is where it's different than ACf
    // get terms so we can look at the parents
    if (is_array($terms)) {
        foreach ($terms as $index => $term_id) {
            $terms[$index] = get_term_by('id', intval($term_id), $term->taxonomy);
        }
    }
    if (!is_array($terms) && $options['post_id']) {
        $terms = wp_get_post_terms(intval($options['post_id']), $term->taxonomy);
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $terms = array_filter($terms);
    $match = false;
    // collect a list of ancestors
    $ancestors = array();
    if (count($terms)) {
        foreach ($terms as $term_to_check) {
            $ancestors = array_merge(get_ancestors($term_to_check->term_id, $term->taxonomy));
        }
        // end foreach terms
    }
    // end if
    // see if the rule matches any term ancetor
    if ($term && in_array($term->term_id, $ancestors)) {
        $match = true;
    }
    if ($rule['operator'] == '!=') {
        // reverse the result
        $match = !$match;
    }
    return $match;
}
开发者ID:Hube2,项目名称:acf-filters-and-functions,代码行数:43,代码来源:acf-post-category-ancestor-location-rule.php

示例2: acf_decode_taxonomy_terms

function acf_decode_taxonomy_terms($terms = false)
{
    // load all taxonomies if not specified in args
    if (!$terms) {
        $terms = acf_get_taxonomy_terms();
    }
    // vars
    $r = array();
    foreach ($terms as $term) {
        // vars
        $data = acf_decode_taxonomy_term($term);
        // create empty array
        if (!array_key_exists($data['taxonomy'], $r)) {
            $r[$data['taxonomy']] = array();
        }
        // append to taxonomy
        $r[$data['taxonomy']][] = $data['term'];
    }
    // return
    return $r;
}
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:21,代码来源:api-helpers.php

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

示例4: rule_match_post_taxonomy

 function rule_match_post_taxonomy($match, $rule, $options)
 {
     // bail early if not a post
     if (!$options['post_id']) {
         return false;
     }
     // vars
     $terms = $options['post_taxonomy'];
     // get term data
     // - selected term may have a numeric slug '123' (user reported on forum), so always check slug first
     $data = acf_decode_taxonomy_term($rule['value']);
     $term = get_term_by('slug', $data['term'], $data['taxonomy']);
     // attempt get term via ID (ACF4 uses ID)
     if (!$term && is_numeric($data['term'])) {
         $term = get_term_by('id', $data['term'], $data['taxonomy']);
     }
     // bail early if no term
     if (!$term) {
         return false;
     }
     // post type
     if (!$options['post_type']) {
         $options['post_type'] = get_post_type($options['post_id']);
     }
     // get terms
     // - allow an empty array (sent via JS) to avoid loading the real post's terms
     if (!is_array($terms)) {
         $terms = wp_get_post_terms($options['post_id'], $term->taxonomy, array('fields' => 'ids'));
     }
     // If no terms, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
     if (empty($terms)) {
         if (is_object_in_taxonomy($options['post_type'], 'category')) {
             $terms = array(1);
         }
     }
     // compare
     if ($rule['operator'] == "==") {
         $match = in_array($term->term_id, $terms);
     } elseif ($rule['operator'] == "!=") {
         $match = !in_array($term->term_id, $terms);
     }
     // return
     return $match;
 }
开发者ID:darbymanning,项目名称:Family-Church,代码行数:44,代码来源:location.php

示例5: acf_decode_taxonomy_terms

function acf_decode_taxonomy_terms($strings = false)
{
    // bail early if no terms
    if (empty($strings)) {
        return false;
    }
    // vars
    $terms = array();
    // loop
    foreach ($strings as $string) {
        // vars
        $data = acf_decode_taxonomy_term($string);
        $taxonomy = $data['taxonomy'];
        $term = $data['term'];
        // create empty array
        if (!isset($terms[$taxonomy])) {
            $terms[$taxonomy] = array();
        }
        // append
        $terms[$taxonomy][] = $term;
    }
    // return
    return $terms;
}
开发者ID:Garth619,项目名称:Femi9,代码行数:24,代码来源:api-helpers.php

示例6: rule_match_post_taxonomy

 function rule_match_post_taxonomy($match, $rule, $options)
 {
     // validate
     if (!$options['post_id']) {
         return false;
     }
     // vars
     $terms = $options['post_taxonomy'];
     // get term data
     $data = acf_decode_taxonomy_term($rule['value']);
     $field = is_numeric($data['term']) ? 'id' : 'slug';
     $term = get_term_by($field, $data['term'], $data['taxonomy']);
     // validate term
     if (empty($term)) {
         return false;
     }
     // post type
     if (!$options['post_type']) {
         $options['post_type'] = get_post_type($options['post_id']);
     }
     // get terms
     if (!$options['ajax']) {
         $terms = wp_get_post_terms($options['post_id'], $term->taxonomy, array('fields' => 'ids'));
     }
     // If no terms, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
     if (empty($terms)) {
         if (is_object_in_taxonomy($options['post_type'], 'category')) {
             $terms = array(1);
         }
     }
     // compare
     if ($rule['operator'] == "==") {
         $match = in_array($term->term_id, $terms);
     } elseif ($rule['operator'] == "!=") {
         $match = !in_array($term->term_id, $terms);
     }
     // return
     return $match;
 }
开发者ID:bmavus,项目名称:wp-theme-blank,代码行数:39,代码来源:location.php

示例7: get_ajax_query

 function get_ajax_query($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'field_key' => '', 'paged' => 1, 'post_type' => '', 'taxonomy' => ''));
     // 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($options['post_type'])) {
         $args['post_type'] = acf_get_array($options['post_type']);
     } elseif (!empty($field['post_type'])) {
         $args['post_type'] = acf_get_array($field['post_type']);
     } else {
         $args['post_type'] = acf_get_post_types();
     }
     // taxonomy
     if (!empty($options['taxonomy'])) {
         // vars
         $term = acf_decode_taxonomy_term($options['taxonomy']);
         // tax query
         $args['tax_query'] = array();
         // append
         $args['tax_query'][] = array('taxonomy' => $term['taxonomy'], 'field' => 'slug', 'terms' => $term['term']);
     } elseif (!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/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);
     // 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']);
         }
         // 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;
     }
     // add as optgroup or results
     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,代码行数:91,代码来源:relationship.php


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