【WordPress】PHPプログラムからAdvanced Custom Fieldsの繰り返しフィールドに値を保存する方法

データベースへの保存方法

update_post_meta関数を使う。

  • update_post_meta(投稿ID, 繰り返しフィールドのフィールド名, サブフィールドの件数);
  • update_post_meta(投稿ID, 繰り返しフィールドのフィールド名_連番_サブフィールドのフィールド名, データ);
    ※連番は0から始まる

サンプル

繰り返しフィールドのフィールド名がitems、サブフィールドのフィールド名がitemの場合

update_post_meta(1, 'items', 3);
update_post_meta(1, 'items_0_item', 'データ1');
update_post_meta(1, 'items_1_item', 'データ2');
update_post_meta(1, 'items_2_item', 'データ3');

参考サイト(2020/7/9更新)

https://www.advancedcustomfields.com/resources/repeater/#faq

https://support.advancedcustomfields.com/forums/topic/adding-repeater-field-with-update_post_meta/

【1つ新しい記事】

【1つ古い記事】

この記事へのコメント

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です