Title: カスタム投稿に紐づけたACFの画像の取得について
Last modified: 2021年5月21日

---

# カスタム投稿に紐づけたACFの画像の取得について

 *  解決済 [totete](https://ja.wordpress.org/support/users/totete/)
 * (@totete)
 * [5年、 5ヶ月前](https://ja.wordpress.org/support/topic/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%81%ab%e7%b4%90%e3%81%a5%e3%81%91%e3%81%9facf%e3%81%ae%e7%94%bb%e5%83%8f%e3%81%ae%e5%8f%96%e5%be%97%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/)
 * sampleというカスタム投稿を作成。
    Advanced Custom Fieldsでsample_thumbという画像
   のカスタムフィールドを作成。 返り値のフォーマットは画像IDに設定しました。
 * このカスタム投稿のページの一覧を取得して、sample_thumbの画像を表示させたいのですが、
   うまくいきません。
    ページIDの取得が必要だと思うのですが、うまく取得できません。
   どこが間違ってるのかわかるいらっしゃいますでしょうか？
 *     ```
       <?php		
       $myposts = get_posts(array(
       	'post_type' => 'sample',
       	'order' => 'DESC',
       	'posts_per_page' => -1
       ));
       if($myposts){ ?>
       <?php foreach($myposts as $post): setup_postdata($post); ?>
       <div class="sample_item">
       <?php
       	$sample_thumb = get_field('sample_thumb',$post->id);
       	$images = wp_get_attachment_image_src($sample_thumb, 'full');
       	$img_alt = get_post(get_field('sample_thumb'));
       	$alt = get_post_meta($img_alt->ID, '_wp_attachment_image_alt', true);
       	if($sample_thumb){ ?>
       	<img src="<?= $images[0]; ?>" width="<?= $images[1]; ?>" height="<?= $images[2]; ?>" alt="<?php if($alt){ echo $alt; } else { echo the_title_attribute(); }?>">
       <?php } ?>
       	</div>
       <?php endforeach; wp_reset_postdata(); } ?>
       ```
   

1件の返信を表示中 - 1 - 1件目 (全1件中)

 *  トピック投稿者 [totete](https://ja.wordpress.org/support/users/totete/)
 * (@totete)
 * [5年、 5ヶ月前](https://ja.wordpress.org/support/topic/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%81%ab%e7%b4%90%e3%81%a5%e3%81%91%e3%81%9facf%e3%81%ae%e7%94%bb%e5%83%8f%e3%81%ae%e5%8f%96%e5%be%97%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/#post-11671797)
 * すみません。取得出来てないと思ったら取得出来てました。

1件の返信を表示中 - 1 - 1件目 (全1件中)

 トピック「カスタム投稿に紐づけたACFの画像の取得について」には新たに返信すること
はできません。

## タグ

 * [Advanced Custom Fields](https://ja.wordpress.org/support/topic-tag/advanced-custom-fields/)
 * [画像](https://ja.wordpress.org/support/topic-tag/%e7%94%bb%e5%83%8f/)

 * フォーラム: [プラグイン](https://ja.wordpress.org/support/forum/plugins/)
 * 1件の返信
 * 1人の参加者
 * 最後の返信者: [totete](https://ja.wordpress.org/support/users/totete/)
 * 最後の活動: [5年、 5ヶ月前](https://ja.wordpress.org/support/topic/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%81%ab%e7%b4%90%e3%81%a5%e3%81%91%e3%81%9facf%e3%81%ae%e7%94%bb%e5%83%8f%e3%81%ae%e5%8f%96%e5%be%97%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/#post-11671797)
 * 状態: 解決済

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
