ACF:从关系字段加载转发器字段

时间:2015-11-16 15:27:30

标签: php wordpress advanced-custom-fields

我尝试使用高级自定义字段从相关帖子加载转发器字段。

我有一个帖子与另一个post_type加载帖子有关系。然后这个post_type有一个repeater_field。我试图加载我相关帖子的这些repeater_fields。它是另一个对象内的一个对象。

这是我的代码:

<?php 
  $posts = get_field('related_posts'); // this is a relation field
  if( $posts ): 
  foreach( $posts as $p ): 
?>

    <section class="slider">
        <?php 
            $quotes = get_field('slider_quotes'); // this is my repeater field

            if( have_rows($quotes) ):
                while ( have_rows($quotes) ) : the_row();
        ?>
      <div><h2><?php echo get_sub_field('quote'); ?></h2></div>

       <?php endwhile; else: 
                echo "Nothing yet"; 
        endif; ?>

    </section>

我已经尝试过:

$frases = get_field('slider_quotes', $p->ID);

<?php echo get_sub_field('quotes', $p->ID); ?>

我一无所获。

谢谢!

完整代码

https://gist.github.com/pailoro/1541717925d9cd9622ba

1 个答案:

答案 0 :(得分:0)

如果'slider_quotes'是转发器字段,请尝试使用

<?php the_repeater_field('slider_quotes', $p->ID); ?>

参考link to get values of repeater field