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


PHP acf_get_posts函数代码示例

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


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

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_force_type_array($value);
     // convert to int
     $value = array_map('intval', $value);
     // load posts if needed
     if ($field['return_format'] == 'object') {
         // get posts
         $value = acf_get_posts(array('post__in' => $value, 'post_type' => $field['post_type']));
     }
     // return
     return $value;
 }
开发者ID:quangnpd,项目名称:jobshop_web,代码行数:18,代码来源:relationship.php

示例3: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         // return false as $value may be '' (from DB) which doesn't make much sense
         return false;
     }
     // get posts
     $posts = acf_get_posts(array('post_type' => 'attachment', 'post__in' => $value));
     // update value to include $post
     foreach (array_keys($posts) as $i) {
         $posts[$i] = acf_get_attachment($posts[$i]);
     }
     // return
     return $posts;
 }
开发者ID:TMBR,项目名称:johnjohn,代码行数:16,代码来源:gallery.php

示例4: get_posts

 function get_posts($value, $field)
 {
     // force value to array
     $value = acf_get_array($value);
     // get selected post ID's
     $post__in = array();
     foreach ($value as $k => $v) {
         if (is_numeric($v)) {
             // append to $post__in
             $post__in[] = (int) $v;
         }
     }
     // bail early if no posts
     if (empty($post__in)) {
         return $value;
     }
     // get posts
     $posts = acf_get_posts(array('post__in' => $post__in, 'post_type' => $field['post_type']));
     // override value with post
     $return = array();
     // append to $return
     foreach ($value as $k => $v) {
         if (is_numeric($v)) {
             // extract first post
             $post = array_shift($posts);
             // append
             if ($post) {
                 $return[] = $post;
             }
         } else {
             $return[] = $v;
         }
     }
     // return
     return $return;
 }
开发者ID:de190909,项目名称:WPTest,代码行数:36,代码来源:page_link.php

示例5: get_attachments

 function get_attachments($value)
 {
     // bail early if no value
     if (empty($value)) {
         return false;
     }
     // force value to array
     $post__in = acf_get_array($value);
     // get posts
     $posts = acf_get_posts(array('post_type' => 'attachment', 'post__in' => $post__in));
     // return
     return $posts;
 }
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:13,代码来源:gallery.php

示例6: get_posts

 function get_posts($value, $field)
 {
     // numeric
     $value = acf_get_numeric($value);
     // bail early if no value
     if (empty($value)) {
         return false;
     }
     // get posts
     $posts = acf_get_posts(array('post__in' => $value, 'post_type' => $field['post_type']));
     // return
     return $posts;
 }
开发者ID:Garth619,项目名称:Femi9,代码行数:13,代码来源:post_object.php

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

示例8: get_posts

 function get_posts($value)
 {
     // force value to array
     $value = acf_force_type_array($value);
     // get selected post ID's
     $post__in = array();
     foreach (array_keys($value) as $k) {
         if (is_numeric($value[$k])) {
             // convert to int
             $value[$k] = intval($value[$k]);
             // append to $post__in
             $post__in[] = $value[$k];
         }
     }
     // bail early if no posts
     if (empty($post__in)) {
         return $value;
     }
     // get posts
     $posts = acf_get_posts(array('post__in' => $post__in));
     // override value with post
     $return = array();
     // append to $return
     foreach ($value as $k => $v) {
         if (is_numeric($v)) {
             // find matching $post
             foreach ($posts as $post) {
                 if ($post->ID == $v) {
                     $return[] = $post;
                     break;
                 }
             }
         } else {
             $return[] = $v;
         }
     }
     // return
     return $return;
 }
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:39,代码来源:page_link.php

示例9: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_force_type_array($value);
     // convert values to int
     $value = array_map('intval', $value);
     // load posts if needed
     if ($field['return_format'] == 'object') {
         // get posts
         $value = acf_get_posts(array('post__in' => $value));
     }
     // convert back from array if neccessary
     if (!$field['multiple']) {
         $value = array_shift($value);
     }
     // return value
     return $value;
 }
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:22,代码来源:post_object.php

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


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