Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将ACF值拉入自定义post类型存档_Php_Custom Post Type_Advanced Custom Fields - Fatal编程技术网

Php 如何将ACF值拉入自定义post类型存档

Php 如何将ACF值拉入自定义post类型存档,php,custom-post-type,advanced-custom-fields,Php,Custom Post Type,Advanced Custom Fields,所以我的问题是,我刚刚创建了一个自定义的帖子类型,并创建了几个帖子来配合这个。我正在使用我创建的模板single-post_type.php中的ACF字段。这些在单个帖子上显示得很好,但是我需要在单个帖子页面上的一些ACF字段值显示在自定义帖子索引上。我试着寻找答案,但似乎找不到我想要的 以下是我注册自定义帖子类型的代码,以供参考: // Add new post type for Available Homes add_action('init', 'available_homes'); fu

所以我的问题是,我刚刚创建了一个自定义的帖子类型,并创建了几个帖子来配合这个。我正在使用我创建的模板single-post_type.php中的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);
}
我在single-available_homes.php上有一些基本的ACF字段

然后我有一个名为archive-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字段和其他所有内容在各个帖子上都运行良好,但我不知道如何才能在归档页面上显示ACF字段数据。帮助?

您是否研究过如何在此处发布其他页面中的字段:


这可能就是您要查找的内容。

ACF字段必须在循环中。您的
archive-available\u homes.php
文件没有循环,它调用

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

你可以使用我的插件
ACF CPT选项页面


2020-我用这个插件在几分钟内就完成了:

您应该将它作为ACF的附加组件提交。这可以帮助很多人!编辑:在我发布这篇文章之后,改变了标签,向下滚动,然后在附加列表页面上看到了它……现在它在这里,这就是答案。请注意,如果您想为归档页面提供一些特定选项,您可以选择创建ACF选项页面(在PRO中提供)。
<?php get_template_part( 'content', 'available_homes' );     ?>