WordPressのプラグイン[Advanced Custom Fields]の有料アドオン(Repeater Field)の表示方法の一例を紹介します。
リピーターフィールドの基本的な表示方法
<?php if(have_rows('repeater_field_name')): ?> <?php while(have_rows('repeater_field_name')): the_row(); ?> <?php the_sub_field('sub_field_name'); ?> <?php endwhile; ?> <?php endif; ?>
指定したカテゴリーのリピーターフィールド情報を取り出し表示する方法
<div> <?php $args = array( 'posts_per_page' => 10,//表示件数 'cat' => 5,//カテゴリーID 'post_status' => 'publish', ); ?> <ul> <?php $loop = new WP_Query($args); while ( $loop->have_posts() ) : $loop->the_post(); ?> <li> <?php if(get_field('repeater_field_name')): ?> <?php while(the_repeater_field('repeater_field_name')): ?> <p><?php the_sub_field('sub_field_name'); ?></p> <?php endwhile; ?> <?php endif; ?> <p><?php echo mb_substr(get_field('field_name'), 0,50); ?>…</p> </li> <?php endwhile; wp_reset_postdata(); ?> <ul> </div>