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


PHP acf_get_post_types函数代码示例

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


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

示例1: render_location_value

 function render_location_value($options)
 {
     // vars
     $options = wp_parse_args($options, array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null));
     // vars
     $choices = array();
     // some case's have the same outcome
     if ($options['param'] == "page_parent") {
         $options['param'] = "page";
     }
     switch ($options['param']) {
         /*
          *  Basic
          */
         case "post_type":
             // all post types except attachment
             $exclude = array('attachment');
             $choices = acf_get_post_types($exclude);
             $choices = acf_get_pretty_post_types($choices);
             break;
         case "user_type":
             global $wp_roles;
             $choices = $wp_roles->get_names();
             if (is_multisite()) {
                 $choices['super_admin'] = __('Super Admin');
             }
             break;
             /*
              *  Post
              */
         /*
          *  Post
          */
         case "post":
             // get post types
             $exclude = array('page', 'attachment');
             $post_types = acf_get_post_types($exclude);
             // get posts grouped by post type
             $groups = acf_get_posts(array('post_type' => $post_types));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices[$group_title] = $posts;
                 }
             }
             break;
         case "post_category":
             $terms = acf_get_taxonomy_terms('category');
             if (!empty($terms)) {
                 $choices = array_pop($terms);
             }
             break;
         case "post_format":
             $choices = get_post_format_strings();
             break;
         case "post_status":
             $choices = array('publish' => __('Publish', 'acf'), 'pending' => __('Pending Review', 'acf'), 'draft' => __('Draft', 'acf'), 'future' => __('Future', 'acf'), 'private' => __('Private', 'acf'), 'inherit' => __('Revision', 'acf'), 'trash' => __('Trash', 'acf'));
             break;
         case "post_taxonomy":
             $choices = acf_get_taxonomy_terms();
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
             /*
              *  Page
              */
         /*
          *  Page
          */
         case "page":
             // get posts grouped by post type
             $groups = acf_get_posts(array('post_type' => 'page'));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices = $posts;
                 }
             }
             break;
         case "page_type":
             $choices = array('front_page' => __("Front Page", 'acf'), 'posts_page' => __("Posts Page", 'acf'), 'top_level' => __("Top Level Page (parent of 0)", 'acf'), 'parent' => __("Parent Page (has children)", 'acf'), 'child' => __("Child Page (has parent)", 'acf'));
             break;
         case "page_parent":
             // refer to "page"
//.........这里部分代码省略.........
开发者ID:eea76,项目名称:hammer,代码行数:101,代码来源:field-group.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: acf_get_posts

function acf_get_posts($args = array())
{
    // vars
    $posts = array();
    // defaults
    // leave suppress_filters as true becuase we don't want any plugins to modify the query as we know exactly what
    $args = acf_parse_args($args, array('posts_per_page' => -1, 'post_type' => acf_get_post_types(), 'post_status' => 'any'));
    // validate post__in
    if ($args['post__in']) {
        // force value to array
        $args['post__in'] = acf_force_type_array($args['post__in']);
        // convert to int
        $args['post__in'] = array_map('intval', $args['post__in']);
        // add filter to remove post_type
        // use 'query' filter so that 'suppress_filters' can remain true
        add_filter('query', '_acf_get_posts_query');
        // order by post__in
        $args['orderby'] = 'post__in';
    }
    // load posts in 1 query to save multiple DB calls from following code
    $posts = get_posts($args);
    // validate order
    if ($posts && $args['post__in']) {
        // vars
        $order = array();
        // generate sort order
        foreach ($posts as $i => $post) {
            $order[$i] = array_search($post->ID, $args['post__in']);
        }
        // sort
        array_multisort($order, $posts);
    }
    // return
    return $posts;
}
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:35,代码来源:api-helpers.php

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

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

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

示例7: get_posts

 function get_posts($value)
 {
     // force value to array
     $value = acf_force_type_array($value);
     // convert to int
     $value = array_map('intval', $value);
     // load posts in 1 query to save multiple DB calls from following code
     if (count($value) > 1) {
         get_posts(array('posts_per_page' => -1, 'post_type' => acf_get_post_types(), 'post_status' => 'any', 'post__in' => $value));
     }
     // vars
     $posts = array();
     // update value to include $post
     foreach ($value as $post_id) {
         if ($post = get_post($post_id)) {
             $posts[] = $post;
         }
     }
     // return
     return $posts;
 }
开发者ID:adnandot,项目名称:intenseburn,代码行数:21,代码来源:post_object.php

示例8: acf_get_pretty_post_types

function acf_get_pretty_post_types($post_types = array())
{
    // get post types
    if (empty($post_types)) {
        // get all custom post types
        $post_types = acf_get_post_types();
    }
    // get labels
    $ref = array();
    $r = array();
    foreach ($post_types as $post_type) {
        // vars
        $label = $post_type;
        // check that object exists (case exists when importing field group from another install and post type does not exist)
        if (post_type_exists($post_type)) {
            $obj = get_post_type_object($post_type);
            $label = $obj->labels->singular_name;
        }
        // append to r
        $r[$post_type] = $label;
        // increase counter
        if (!isset($ref[$label])) {
            $ref[$label] = 0;
        }
        $ref[$label]++;
    }
    // get slugs
    foreach (array_keys($r) as $i) {
        // vars
        $post_type = $r[$i];
        if ($ref[$post_type] > 1) {
            $r[$i] .= ' (' . $i . ')';
        }
    }
    // return
    return $r;
}
开发者ID:mariussunde,项目名称:Sn-hetta-Designmanual-WP-Theme,代码行数:37,代码来源:api-helpers.php

示例9: 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_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:sdh100shaun,项目名称:pantheon,代码行数:81,代码来源:post_object.php

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

示例11: acf_get_pretty_post_types

function acf_get_pretty_post_types($post_types = array())
{
    // get post types
    if (empty($post_types)) {
        // get all custom post types
        $post_types = acf_get_post_types();
    }
    // get labels
    $ref = array();
    $r = array();
    foreach (array_keys($post_types) as $i) {
        // vars
        $post_type = acf_extract_var($post_types, $i);
        $obj = get_post_type_object($post_type);
        $name = $obj->labels->singular_name;
        // append to r
        $r[$post_type] = $name;
        // increase counter
        if (!isset($ref[$name])) {
            $ref[$name] = 0;
        }
        $ref[$name]++;
    }
    // get slugs
    foreach (array_keys($r) as $i) {
        // vars
        $post_type = $r[$i];
        if ($ref[$post_type] > 1) {
            $r[$i] .= ' (' . $i . ')';
        }
    }
    // return
    return $r;
}
开发者ID:pellio11,项目名称:ns-select-project,代码行数:34,代码来源:api-helpers.php

示例12: array

    // 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;
    }
}
// post type filter
$post_types = array();
if ($width['post_type']) {
    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'])) {
开发者ID:NiviJah,项目名称:acf-api-fields,代码行数:31,代码来源:relationship.php

示例13: render_location_value

 function render_location_value($options)
 {
     // vars
     $options = wp_parse_args($options, array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null));
     // vars
     $choices = array();
     // some case's have the same outcome
     if ($options['param'] == "page_parent") {
         $options['param'] = "page";
     }
     switch ($options['param']) {
         /*
          *  Post
          */
         case "post_type":
             // get post types
             $post_types = acf_get_post_types(array('show_ui' => 1, 'exclude' => array('attachment')));
             // get choices
             $choices = acf_get_pretty_post_types($post_types);
             // end
             break;
         case "post":
             // get post types
             $post_types = acf_get_post_types(array('exclude' => array('page', 'attachment')));
             // get posts grouped by post type
             $groups = acf_get_grouped_posts(array('post_type' => $post_types));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices[$group_title] = $posts;
                 }
             }
             break;
         case "post_template":
             // vars
             $templates = wp_get_theme()->get_post_templates();
             $default = apply_filters('default_page_template_title', __('Default Template', 'acf'));
             // choices
             $choices = array('default' => $default);
             // templates
             if (!empty($templates)) {
                 foreach ($templates as $post_type => $post_type_templates) {
                     $choices = array_merge($choices, $post_type_templates);
                 }
             }
             // break
             break;
         case "post_category":
             $terms = acf_get_taxonomy_terms('category');
             if (!empty($terms)) {
                 $choices = array_pop($terms);
             }
             break;
         case "post_format":
             $choices = get_post_format_strings();
             break;
         case "post_status":
             global $wp_post_statuses;
             if (!empty($wp_post_statuses)) {
                 foreach ($wp_post_statuses as $status) {
                     $choices[$status->name] = $status->label;
                 }
             }
             break;
         case "post_taxonomy":
             $choices = acf_get_taxonomy_terms();
             // unset post_format
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
             /*
              *  Page
              */
         /*
          *  Page
          */
         case "page":
             // get posts grouped by post type
             $groups = acf_get_grouped_posts(array('post_type' => 'page'));
             if (!empty($groups)) {
                 foreach (array_keys($groups) as $group_title) {
                     // vars
                     $posts = acf_extract_var($groups, $group_title);
                     // override post data
                     foreach (array_keys($posts) as $post_id) {
                         // update
                         $posts[$post_id] = acf_get_post_title($posts[$post_id]);
                     }
                     // append to $choices
                     $choices = $posts;
                 }
             }
//.........这里部分代码省略.........
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:101,代码来源:field-group.php

示例14: location_page_type_rule_match

 /**
  * Match modified values for "Page Type" location rule
  *
  * @param  bool   $match    The true / false variable which must be returned.
  * @param  array  $rule     The current rule that you are matching against.
  * @param  array  $options  Data about the current edit screen, includes any data posted in an AJAX call.
  * @return bool   $match
  */
 public static function location_page_type_rule_match($match, $rule = [], $options = [])
 {
     if ('archives' === $rule['value']) {
         if (empty($options['post_id'])) {
             return false;
         }
         $post = get_post($options['post_id']);
         // Test for Post Archive
         $archive_page = (int) get_option('page_for_posts');
         if ($post->ID != $archive_page) {
             $boilerplate_options = get_option('boilerplate', []);
             if (empty($boilerplate_options)) {
                 return false;
             }
             $exclude = ['post', 'attachment', 'polylang_mo'];
             $post_types = acf_get_post_types($exclude);
             foreach ($post_types as $post_type) {
                 $archive_page = 0;
                 $obj = get_post_type_object($post_type);
                 if (!isset($obj->has_archive) || !$obj->has_archive) {
                     continue;
                 }
                 if (empty($obj->labels->page_for_items_setting) || empty($boilerplate_options[$obj->labels->page_for_items_setting])) {
                     continue;
                 }
                 $archive_page = (int) $boilerplate_options[$obj->labels->page_for_items_setting];
                 if ($post->ID == $archive_page) {
                     break;
                 }
             }
         }
         if ($post->ID == $archive_page) {
             if ($rule['operator'] === '==') {
                 return true;
             } elseif ($rule['operator'] === '!=') {
                 return false;
             }
         } else {
             return true;
         }
     }
     return $match;
 }
开发者ID:locomotivemtl,项目名称:wordpress-boilerplate,代码行数:51,代码来源:acf.php


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