Advanced Custom Fields 繰り返しフィールドの値を1つずつ

情報を追記している場合はありますが、古い情報を訂正はしていませんので、公開年月日を参照してください。プラグイン・タグ、いずれもワードプレス・PHPのバージョン等によって動作しない場合もあります。

繰り返しの画像フィールド、上限3つで、3つめがなくてもHTMLタグは出したいので、値を1つずつ取ることに。
$rows で繰り返しフィールドの値をとって、サブフィールドの1つ目は$rows[0]

<?php $rows = get_field('repeater'); ?><tr><td><?php $first = $rows[0]; $first_image = $first['image']; $image = wp_get_attachment_image_src( $first_image, 'medium' ); if($image) { ?><img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" alt="xxxx" /><?php } ?></td>
<td><?php $second = $rows[1]; $second_image = $second['image']; $image = wp_get_attachment_image_src( $second_image, 'medium' ); if($image) { ?><img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" alt="xxxx" /><?php } ?></td>
<td><?php $third = $rows[2]; $third_image = $third['image']; $image = wp_get_attachment_image_src( $third_image, 'medium' ); if($image) { ?><img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" alt="xxxx" /><?php } ?></td></tr>

その他のAdvanced Custom Fields に関する記事一覧

Advanced Custom Fields に関する記事一覧ページへ