在子页面上显示 ACF 转发器字段



我想在子页面上显示 ACF 中继器字段的结果。当前代码的示例:

<?php if( have_rows('recommended-properties') ): ?>
  <?php while ( have_rows('recommended-properties') ) : the_row(); ?>
    <?php the_sub_field('recommended-properties-title'); ?>
    <?php the_sub_field('recommended-properties-description'); ?>
  <?php endwhile; ?>
<?php endif; ?>

现在,我想我可以将父页面 ID 存储在一个变量中,并以与从另一篇文章中获取值相同的方式使用它(请参阅:http://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/)

我尝试了以下方法:

<?php $parentPageId = wp_get_post_parent_id( $post_ID ); ?>
<?php if( have_rows('recommended-properties', echo $parentPageId;) ): ?>
  <?php while ( have_rows('recommended-properties', echo $parentPageId;) ) : the_row(); ?>
    <?php the_sub_field('recommended-properties-title'); ?>
    <?php the_sub_field('recommended-properties-description'); ?>
  <?php endwhile; ?>
<?php endif; ?>

但不幸的是,没有运气。关于我可以从这里去哪里的任何建议?

非常感谢!

在函数中添加参数时不需要添加回显

尝试以下代码

<?php $parentPageId = wp_get_post_parent_id( $post_ID ); ?>
<?php if( have_rows('recommended-properties', $parentPageId) ): ?>
  <?php while ( have_rows('recommended-properties', $parentPageId) ) : the_row(); ?>
    <?php the_sub_field('recommended-properties-title'); ?>
    <?php the_sub_field('recommended-properties-description'); ?>
  <?php endwhile; ?>
<?php endif; ?>

最新更新