0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【WordPress】「Advanced Custom Fields」を使用して、繰り返しフィールドを表示

Last updated at Posted at 2023-02-08

WordPressのプラグイン「Advanced Custom Fields」を使用して、繰り返しフィールドの表示方法を紹介します。
管理画面(固定ページなど)で決まった項目を繰り返し入力したい時に便利です。
また、管理画面内で並び替えも可能です。

「Advanced Custom Fields Pro」のみで提供されている機能です。

1.フィールドグループを新規追加

「Advanced Custom Fields」の設定から「新規追加」ボタンをクリックして遷移したページにて、「フィールドを追加」ボタンをクリック。
acf_1.png

2.「繰り返しフィールド」を使う

①フィールドタイプで「繰り返しフィールド」を選択。
②サブフィールドの「フィールドを追加」ボタンをクリックして、任意のフィールドタイプを設定。
acf_2.png

3.フィールドを表示するページに記述

繰り返しフィールドを表示するためにはループを使用します。
以下のコードをフィールドを表示するphpファイルに記述したら表示完了です!

(例)
リピーターフィールド名 → repeater_field_name
サブフィールド名 → sub_field_name

<?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; ?>

サブフィールドを表示するときは「the_field」ではなく、「the_sub_field」使う。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?