如何将ACF值拉入自定义帖子类型档案

问题描述:

所以我的问题是,我刚刚创建了一个自定义帖子类型,并创建了几个帖子来配合这一点。我在我创建的模板single-post_type.php中使用了ACF字段。这些在单个帖子上显示得很好,但我需要在单个帖子页面上显示的一些ACF字段值显示在自定义帖子索引中。我试过寻找答案,但似乎无法找到我在找什么。如何将ACF值拉入自定义帖子类型档案

供参考,这是我已经注册自定义职位类型代码:

// Add new post type for Available Homes 
add_action('init', 'available_homes'); 
function available_homes() 
{ 
$available_homes_labels = array(
    'name' => _x('Available Homes', 'post type general name'), 
    'singular_name' => _x('Available Home', 'post type singular name'), 
    'all_items' => __('All Available Homes'), 
    'add_new' => _x('Add New Listing', 'recipes'), 
    'add_new_item' => __('Add New Listing'), 
    'edit_item' => __('Edit Listing'), 
    'new_item' => __('New Listing'), 
    'view_item' => __('View Listing'), 
    'search_items' => __('Search in Available Homes'), 
    'not_found' => __('No listings found'), 
    'not_found_in_trash' => __('No listings found in trash'), 
    'parent_item_colon' => '' 
); 
$args = array(
    'labels' => $available_homes_labels, 
    'public' => true, 
    'publicly_queryable' => true, 
    'show_ui' => true, 
    'query_var' => true, 
    'rewrite' => true, 
    'capability_type' => 'post', 
    'hierarchical' => false, 
    'menu_position' => 20, 
    'supports' => array('title','editor','custom-fields'), 
    'has_archive' => 'available_homes' 
); 
register_post_type('available_homes',$args); 
} 

而且我在单available_homes.php一些基本的ACF领域

然后我呼吁存档页-available_homes.php其中有这样的代码:

<?php get_header(); ?> 
<h1 class="page-title">Available Homes</h1> 
    <div id="primary"> 
     <div id="content" role="main"> 

     <?php if (have_posts()) : ?> 

      <?php /* Start the Loop */ ?> 

      <?php while (have_posts('')) : the_post(); ?> 

       <?php get_template_part('content', get_post_type());  ?> 

      <?php endwhile; ?> 

     <?php else : ?> 
      <article id="post-0" class="post no-results not-found"> 
       <header class="entry-header"> 
        <h1 class="entry-title"><?php _e('Nothing Found', 'twentyeleven'); ?></h1> 
       </header><!-- .entry-header --> 
       <div class="entry-content"> 
        <p><?php _e('Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven'); ?></p> 
        <?php get_search_form(); ?> 
       </div><!-- .entry-content --> 
      </article><!-- #post-0 --> 
     <?php endif; ?> 

     </div><!-- #content --> 
    </div><!-- #primary --> 
<div class="widget_area"> 
<?php dynamic_sidebar("gravity_form_widget_area"); ?> 
</div> 
<?php get_footer(); ?> 

ACF领域和其他一切工作的个别职位不错,但我只是不知道该怎么做才能在A CF字段数据显示在存档页面上。帮帮我?

有你看着如何从其他页面在这里发布字段:http://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/

这可能是你在找什么。

ACF字段必须在循环中。您archive-available_homes.php文件没有一个循环,它调用

<?php get_template_part('content', get_post_type());  ?> 

所以这是你必须添加要呈现的字段content.php。 否则,您可以创建自己的content-available_homes.php文件,并调用:

<?php get_template_part('content', 'available_homes');  ?> 

U可以使用我的插件ACF CPT Options Pages

Download here

+0

您应该提交这作为一个附加上ACF。这可以帮助很多人! 编辑︰和字面上正确后,我发布了这个,改变标签,向下滚动,然后在附加列表页面上看到它.... – DOCbrand

+0

现在它在这里https://uk.wordpress.org/plugins/acf -cpt - 选项 - 页/ –