遍历wordpress中的ACF转发器行并分别显示每一行

Loop through ACF repeater rows in wordpress and display each row separately

我有一个名为 sub_seminars 的 ACF 转发器字段。 在某些 post 中,转发器有多行。 我想遍历行并根据子字段 "start_date"

分别显示每个 post

我正在做这样的事情

<?php
                            $count = 0;
                                $your_repeater = get_field('sub_seminars');
                                if($your_repeater){
                                while( have_rows('sub_seminars') ): the_row();
                                $count++;
                                $my_field = get_sub_field('start_date');
                                if ($count == 1) { ?>



                                <?php while ( have_posts() ) : the_post(); ?>

                                                        <?php
                            // populate config with current post settings
                            presscore_populate_post_config();

                            presscore_get_template_part( 'theme', 'blog/list/blog-list-post' );
                            ?>

                               <?php endwhile; ?>

                        <?php } endwhile;  } ?>

但它适用于第一个 post 即计数 ==1 并且当您增加计数时失败

改变

if ($count == 1) {

if ($count > 1) {

如果您处于第一次迭代,看起来您只需要 运行 循环来检索字段。

 <?php
                $seminarid    = get_the_ID();
                $sub_seminars = get_field( 'sub_seminars', $seminarid );

               for ($nidu = 0; $nidu < count( $sub_seminars ); $nidu ++ ){

 ///////// Place your code here /////////////

} ?>

这是行得通的。