我在WordPress中使用ACF。
我有一个名为Projects
. 在那里,用户可以选择通过 ACF 转发器字段上传2 个特色图像。
现在,在主页上,我为用户提供了从Projects post type中选择8 个 Post Object's的选项。
我需要能够遍历这个主页转发器字段,并从每个“项目”帖子对象中提取特色图像和项目标题。
ACF 最近贬低了repeater_field
我认为它让我失望的功能。
但是,到目前为止,这是我一直在尝试使用的内容:
<!-- check for repeater field -->
<?php if(get_field('featured-projects')): ?>
<?php while(has_sub_field('featured-projects')): ?>
<!-- get project post objects -->
<?php $projects = get_sub_field('project'); ?>
<!-- without the loop below, this echo's all 8 projects ID's -->
<?php echo($projects->ID); ?><br />
<!-- when added, only pulls the first project. And limits the echo above to the first ID -->
<?php $loop = new WP_Query( array(
'post_type' => 'projects',
'p' => $projects->ID
) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile; ?>
<?php endwhile; ?>
<?php endif; ?>
我试图评论代码,但如果有什么不合理的地方,请告诉我。