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


PHP acf_get_child_field_from_parent_field函数代码示例

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


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

示例1: query_posts

 function query_posts()
 {
     // vars
     $r = array('next_page_exists' => 1, 'html' => '');
     // options
     $options = array('post_type' => 'all', 'taxonomy' => 'all', 'posts_per_page' => 10, 'paged' => 1, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 's' => '', 'lang' => false, 'update_post_meta_cache' => false, 'field_key' => '', 'nonce' => '', 'ancestor' => false);
     $options = array_merge($options, $_POST);
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         die;
     }
     // WPML
     if ($options['lang']) {
         global $sitepress;
         if (!empty($sitepress)) {
             $sitepress->switch_lang($options['lang']);
         }
     }
     // convert types
     $options['post_type'] = explode(',', $options['post_type']);
     $options['taxonomy'] = explode(',', $options['taxonomy']);
     // load all post types by default
     if (in_array('all', $options['post_type'])) {
         $options['post_type'] = apply_filters('acf/get_post_types', array());
     }
     // attachment doesn't work if it is the only item in an array???
     if (is_array($options['post_type']) && count($options['post_type']) == 1) {
         $options['post_type'] = $options['post_type'][0];
     }
     // create tax queries
     if (!in_array('all', $options['taxonomy'])) {
         // vars
         $taxonomies = array();
         $options['tax_query'] = array();
         foreach ($options['taxonomy'] as $v) {
             // find term (find taxonomy!)
             // $term = array( 0 => $taxonomy, 1 => $term_id )
             $term = explode(':', $v);
             // validate
             if (!is_array($term) || !isset($term[1])) {
                 continue;
             }
             // add to tax array
             $taxonomies[$term[0]][] = $term[1];
         }
         // now create the tax queries
         foreach ($taxonomies as $k => $v) {
             $options['tax_query'][] = array('taxonomy' => $k, 'field' => 'id', 'terms' => $v);
         }
     }
     unset($options['taxonomy']);
     // search
     if ($options['s']) {
         $options['like_title'] = $options['s'];
         add_filter('posts_where', array($this, 'posts_where'), 10, 2);
     }
     unset($options['s']);
     // load field
     $field = array();
     if ($options['ancestor']) {
         $ancestor = apply_filters('acf/load_field', array(), $options['ancestor']);
         $field = acf_get_child_field_from_parent_field($options['field_key'], $ancestor);
     } else {
         $field = apply_filters('acf/load_field', array(), $options['field_key']);
     }
     // get the post from which this field is rendered on
     $the_post = get_post($options['post_id']);
     // filters
     $options = apply_filters('acf/fields/relationship/query', $options, $field, $the_post);
     $options = apply_filters('acf/fields/relationship/query/name=' . $field['_name'], $options, $field, $the_post);
     $options = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $options, $field, $the_post);
     // query
     $wp_query = new WP_Query($options);
     // global
     global $post;
     // loop
     while ($wp_query->have_posts()) {
         $wp_query->the_post();
         // right aligned info
         $title = '<span class="relationship-item-info">';
         if (in_array('post_type', $field['result_elements'])) {
             $post_type_object = get_post_type_object(get_post_type());
             $title .= $post_type_object->labels->singular_name;
         }
         // WPML
         if ($options['lang']) {
             $title .= ' (' . $options['lang'] . ')';
         }
         $title .= '</span>';
         // featured_image
         if (in_array('featured_image', $field['result_elements'])) {
             $image = get_the_post_thumbnail(get_the_ID(), array(21, 21));
             $title .= '<div class="result-thumbnail">' . $image . '</div>';
         }
         // title
         $title .= get_the_title();
         // status
         if (get_post_status() != "publish") {
             $title .= ' (' . get_post_status() . ')';
         }
//.........这里部分代码省略.........
开发者ID:gjaya79,项目名称:urdailynews,代码行数:101,代码来源:relationship.php

示例2: acf_get_child_field_from_parent_field

function acf_get_child_field_from_parent_field($child_name, $parent)
{
    // vars
    $return = false;
    // find child
    if (isset($parent['sub_fields']) && is_array($parent['sub_fields'])) {
        foreach ($parent['sub_fields'] as $child) {
            if ($child['name'] == $child_name || $child['key'] == $child_name) {
                $return = $child;
                break;
            }
            // perhaps child has grand children?
            $grand_child = acf_get_child_field_from_parent_field($child_name, $child);
            if ($grand_child) {
                $return = $grand_child;
                break;
            }
        }
    } elseif (isset($parent['layouts']) && is_array($parent['layouts'])) {
        foreach ($parent['layouts'] as $layout) {
            $child = acf_get_child_field_from_parent_field($child_name, $layout);
            if ($child) {
                $return = $child;
                break;
            }
        }
    }
    // return
    return $return;
}
开发者ID:nihrain,项目名称:accelerate,代码行数:30,代码来源:api.php

示例3: query_posts

 function query_posts()
 {
     // vars
     $r = array('next_page_exists' => 1, 'html' => '');
     // options
     $options = array('post_type' => 'all', 'taxonomy' => 'all', 'posts_per_page' => 10, 'paged' => 1, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 's' => '', 'lang' => false, 'update_post_meta_cache' => false, 'field_key' => '', 'nonce' => '', 'ancestor' => false);
     $options = array_merge($options, $_POST);
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         die;
     }
     // WPML
     if ($options['lang']) {
         global $sitepress;
         if (!empty($sitepress)) {
             $sitepress->switch_lang($options['lang']);
         }
     }
     // convert types
     $options['post_type'] = explode(',', $options['post_type']);
     $options['taxonomy'] = explode(',', $options['taxonomy']);
     // load all post types by default
     if (in_array('all', $options['post_type'])) {
         $options['post_type'] = apply_filters('acf/get_post_types', array());
     }
     // attachment doesn't work if it is the only item in an array???
     if (is_array($options['post_type']) && count($options['post_type']) == 1) {
         $options['post_type'] = $options['post_type'][0];
     }
     // create tax queries
     if (!in_array('all', $options['taxonomy'])) {
         // vars
         $taxonomies = array();
         $options['tax_query'] = array();
         foreach ($options['taxonomy'] as $v) {
             // find term (find taxonomy!)
             // $term = array( 0 => $taxonomy, 1 => $term_id )
             $term = explode(':', $v);
             // validate
             if (!is_array($term) || !isset($term[1])) {
                 continue;
             }
             // add to tax array
             $taxonomies[$term[0]][] = $term[1];
         }
         // now create the tax queries
         foreach ($taxonomies as $k => $v) {
             $options['tax_query'][] = array('taxonomy' => $k, 'field' => 'id', 'terms' => $v);
         }
     }
     unset($options['taxonomy']);
     // load field
     $field = array();
     if ($options['ancestor']) {
         $ancestor = apply_filters('acf/load_field', array(), $options['ancestor']);
         $field = acf_get_child_field_from_parent_field($options['field_key'], $ancestor);
     } else {
         $field = apply_filters('acf/load_field', array(), $options['field_key']);
     }
     // get the post from which this field is rendered on
     $the_post = get_post($options['post_id']);
     // filters
     $options = apply_filters('acf/fields/relationship/query', $options, $field, $the_post);
     $options = apply_filters('acf/fields/relationship/query/name=' . $field['_name'], $options, $field, $the_post);
     $options = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $options, $field, $the_post);
     // query
     $wp_query = new WP_Query($options);
     // global
     global $post;
     // loop
     while ($wp_query->have_posts()) {
         $wp_query->the_post();
         // get title
         $title = $this->get_result($post, $field, $the_post, $options);
         // update html
         $r['html'] .= '<li><a href="' . esc_url(get_permalink($post->ID)) . '" data-post_id="' . esc_attr($post->ID) . '">' . wp_kses_post($title) . '<span class="acf-button-add"></span></a></li>';
     }
     // next page
     if ((int) $options['paged'] >= $wp_query->max_num_pages) {
         $r['next_page_exists'] = 0;
     }
     // reset
     wp_reset_postdata();
     // return JSON
     echo json_encode($r);
     die;
 }
开发者ID:ffffranklin,项目名称:cmarianiantiques,代码行数:87,代码来源:relationship.php

示例4: get_sub_field_object

function get_sub_field_object($child_name)
{
    // no field?
    if (empty($GLOBALS['acf_field'])) {
        return false;
    }
    // vars
    $depth = count($GLOBALS['acf_field']) - 1;
    $parent = $GLOBALS['acf_field'][$depth]['field'];
    // return
    return acf_get_child_field_from_parent_field($child_name, $parent);
}
开发者ID:pwillems,项目名称:mimosa-contents,代码行数:12,代码来源:api.php

示例5: query_posts

 function query_posts()
 {
     // vars
     $options = array('post_type' => 'all', 'taxonomy' => 'all', 'posts_per_page' => 10, 'paged' => 0, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false, 's' => '', 'lang' => false, 'update_post_meta_cache' => false, 'field_key' => '', 'nonce' => '', 'ancestor' => false);
     $options = array_merge($options, $_POST);
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         die(0);
     }
     // WPML
     if ($options['lang']) {
         global $sitepress;
         $sitepress->switch_lang($options['lang']);
     }
     // convert types
     $options['post_type'] = explode(',', $options['post_type']);
     $options['taxonomy'] = explode(',', $options['taxonomy']);
     // load all post types by default
     if (in_array('all', $options['post_type'])) {
         $options['post_type'] = apply_filters('acf/get_post_types', array());
     }
     // attachment doesn't work if it is the only item in an array???
     if (is_array($options['post_type']) && count($options['post_type']) == 1) {
         $options['post_type'] = $options['post_type'][0];
     }
     // create tax queries
     if (!in_array('all', $options['taxonomy'])) {
         // vars
         $taxonomies = array();
         $options['tax_query'] = array();
         foreach ($options['taxonomy'] as $v) {
             // find term (find taxonomy!)
             // $term = array( 0 => $taxonomy, 1 => $term_id )
             $term = explode(':', $v);
             // validate
             if (!is_array($term) || !isset($term[1])) {
                 continue;
             }
             // add to tax array
             $taxonomies[$term[0]][] = $term[1];
         }
         // now create the tax queries
         foreach ($taxonomies as $k => $v) {
             $options['tax_query'][] = array('taxonomy' => $k, 'field' => 'id', 'terms' => $v);
         }
     }
     unset($options['taxonomy']);
     // search
     if ($options['s']) {
         $options['like_title'] = $options['s'];
         add_filter('posts_where', array($this, 'posts_where'), 10, 2);
     }
     unset($options['s']);
     // load field
     $field = array();
     if ($options['ancestor']) {
         $ancestor = apply_filters('acf/load_field', array(), $options['ancestor']);
         $field = acf_get_child_field_from_parent_field($options['field_key'], $ancestor);
     } else {
         $field = apply_filters('acf/load_field', array(), $options['field_key']);
     }
     // get the post from which this field is rendered on
     $the_post = get_post($options['post_id']);
     // filters
     $options = apply_filters('acf/fields/relationship/query', $options, $field, $the_post);
     $options = apply_filters('acf/fields/relationship/query/name=' . $field['name'], $options, $field, $the_post);
     $options = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $options, $field, $the_post);
     $results = '';
     // load the posts
     $posts = get_posts($options);
     if ($posts) {
         foreach ($posts as $p) {
             // right aligned info
             $title = '<span class="relationship-item-info">';
             if (in_array('post_type', $field['result_elements'])) {
                 $title .= $p->post_type;
             }
             // WPML
             if ($options['lang']) {
                 $title .= ' (' . $options['lang'] . ')';
             }
             $title .= '</span>';
             // featured_image
             if (in_array('featured_image', $field['result_elements'])) {
                 $image = get_the_post_thumbnail($p->ID, array(21, 21));
                 $title .= '<div class="result-thumbnail">' . $image . '</div>';
             }
             // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
             $title .= apply_filters('the_title', $p->post_title, $p->ID);
             // status
             if ($p->post_status != "publish") {
                 $title .= " ({$p->post_status})";
             }
             // filters
             $title = apply_filters('acf/fields/relationship/result', $title, $p, $field, $the_post);
             $title = apply_filters('acf/fields/relationship/result/name=' . $field['name'], $title, $p, $field, $the_post);
             $title = apply_filters('acf/fields/relationship/result/key=' . $field['key'], $title, $p, $field, $the_post);
             $results .= '<li><a href="' . get_permalink($p->ID) . '" data-post_id="' . $p->ID . '">' . $title . '<span class="acf-button-add"></span></a></li>';
         }
     }
//.........这里部分代码省略.........
开发者ID:skristi,项目名称:urbantac,代码行数:101,代码来源:relationship.php


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