我有WordPress和ACF。这是我用来显示转发器字段的代码
<?php
// check if the repeater field has rows of data
if( have_rows('lineup') ):
// loop through the rows of data
while ( have_rows('lineup') ) : the_row();
// display a sub field value
echo '<p>';
the_sub_field('stage');
echo ' on ';
the_sub_field('date');
the_sub_field('artists');
echo '</p>';
endwhile;
else :
// no rows found
endif;
?>
如果我注释掉艺术家行(这是关系字段),则输出是阶段和时间的几个段落。如果我保留它,源代码的HTML将在第一个日期结束时停止
我的问题是如何在转发器字段中显示关系字段
由于
答案 0 :(得分:0)
<?php
// check if the repeater field has rows of data
if (have_rows('lineup')):
// loop through the rows of data
while (have_rows('lineup')):
the_row();
// display a sub field value
echo '<p>';
the_sub_field('stage');
echo ' on ';
the_sub_field('date');
echo '</p>';
$myposts = get_sub_field('artists');
if ($myposts):
?>
<ul>
<?php
foreach ($myposts as $post_object):
?>
<li><a href="<?php
echo get_permalink($post_object->ID);
?>"><?php
echo get_the_title($post_object->ID);
?></a></li>
<?php
endforeach;
?>
</ul>
<?php
endif;
endwhile;
else:
// no rows found
endif;
?>