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 5 years have passed since last update.

ACFで設定したフィールド説明文や選択肢をフロントエンドで利用する

Posted at

ACFのカスタムフィールド内の値はACFフィールド用CPT(acf-field)で、ポストのpost_contentにシリアライズ化されて入っている。
WPでは、値がシリアル化されていた場合のみそれを非シリアル化する関数が用意されている。

maybe_unserialize()
https://developer.wordpress.org/reference/functions/maybe_unserialize/

それを利用するとACFフィールドの設定を引き出せる。

$group_ID = '123';
$args = array(
  'post_type' => 'acf-field',
  'post_parent' => $group_ID,
  'posts_per_page' => -1,
  'order' => 'ASC',
  'orderby' => 'menu_order',
);
$query = new WP_Query( $args );

while ( $query->have_posts() ) :
$query->the_post();
$values = $query->post;
$field_obj = maybe_unserialize($values->post_content);

print_r($field_obj);

endwhile;
wp_reset_postdata();
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?