acf_get_field_group_post()


WordPressのacf_get_field_group_post()関数は、ACF(Advanced Custom Fields)プラグインで使用される関数で、指定されたフィールドグループの投稿オブジェクトを取得します。

構文

acf_get_field_group_post( $field_group );
  • $field_group(string|array) — フィールドグループのキー、ID、または配列を指定します。

例1: フィールドグループの投稿オブジェクトを取得

この例では、フィールドグループのキーを使用して投稿オブジェクトを取得します。

$field_group_post = acf_get_field_group_post('group_1234567890abc');

例2: フィールドグループのタイトルを表示

取得したフィールドグループの投稿オブジェクトからタイトルを表示します。

$field_group_post = acf_get_field_group_post('group_1234567890abc'); echo $field_group_post->post_title;

例3: フィールドグループの内容を表示

フィールドグループの内容を表示する例です。

$field_group_post = acf_get_field_group_post('group_1234567890abc'); echo $field_group_post->post_content;

例4: フィールドグループのステータスを確認

フィールドグループのステータスを確認する例です。

$field_group_post = acf_get_field_group_post('group_1234567890abc'); echo $field_group_post->post_status;

例5: フィールドグループの投稿日を表示

フィールドグループの投稿日を表示する例です。

$field_group_post = acf_get_field_group_post('group_1234567890abc'); echo $field_group_post->post_date;

例6: フィールドグループの最終更新日を表示

フィールドグループの最終更新日を表示する例です。

$field_group_post = acf_get_field_group_post('group_1234567890abc'); echo $field_group_post->post_modified;

注意点

  • フィールドグループが存在しない場合、acf_get_field_group_post()nullを返します。
  • フィールドグループのキーやIDが正しくない場合、正しい投稿オブジェクトが取得できない可能性があります。