Title: カスタムポストタイプの記事ページで同じタームの記事を一覧表示
Last modified: 2016年7月30日

---

# カスタムポストタイプの記事ページで同じタームの記事を一覧表示

 *  [k](https://ja.wordpress.org/support/users/sealight/)
 * (@sealight)
 * [11年、 4ヶ月前](https://ja.wordpress.org/support/topic/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%9d%e3%82%b9%e3%83%88%e3%82%bf%e3%82%a4%e3%83%97%e3%81%ae%e8%a8%98%e4%ba%8b%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%a7%e5%90%8c%e3%81%98%e3%82%bf%e3%83%bc%e3%83%a0/)
 * カスタムポストタイプの記事ページで同じタームの記事を一覧表示するさいに
    カスタム
   フィールドの画像を表示させるにはどのように書けば良いのでしょうか？
 * 通常だと下記のようになるのですが、
 * > <?php
   >  $term = array_shift(get_the_terms($post->ID, ‘タクソノミー名’)); ?> 
   > <?php $tax_posts = get_posts(‘post_type=ポストタイプ名&taxonomy=qa_category&
   > term=’.esc_html($term->slug)); if($tax_posts): ?> <h3><?php echo $term->name;?
   > ></h3>
    -  <?php foreach($tax_posts as $tax_post): ?>
       <?php if ($post->ID != $tax_post-
      >ID): ?>
    - 
    -  <?php else: ?>
    - <?php echo esc_html($tax_post->post_title); ?>
    -  <?php endif; ?>
       <?php endforeach; ?>
 * <?php endif; ?>
 * ここにカスタムフィールド(advanced custom fields)で使用する
 * > <?php echo get_custom_img(‘画像’); ?>
 * を書くと現在のページの画像が表示されてしまいます。
 * ご存知の方いらっしゃいましたらご教示ください。

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

 *  [gatespace](https://ja.wordpress.org/support/users/gatespace/)
 * (@gatespace)
 * [11年、 4ヶ月前](https://ja.wordpress.org/support/topic/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%9d%e3%82%b9%e3%83%88%e3%82%bf%e3%82%a4%e3%83%97%e3%81%ae%e8%a8%98%e4%ba%8b%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%a7%e5%90%8c%e3%81%98%e3%82%bf%e3%83%bc%e3%83%a0/#post-206001)
 * `get_custom_img()` という関数はなんですか？
    WordPressの関数ではないようですが。
   Advanced Custom Fieldsでそのページではない投稿のカスタムフィールドを呼び出す場合、
   $post_idを明示しないとだめです
 * [http://www.advancedcustomfields.com/resources/the_field/](http://www.advancedcustomfields.com/resources/the_field/)
 * [http://www.advancedcustomfields.com/resources/image/](http://www.advancedcustomfields.com/resources/image/)
 *  トピック投稿者 [k](https://ja.wordpress.org/support/users/sealight/)
 * (@sealight)
 * [11年、 4ヶ月前](https://ja.wordpress.org/support/topic/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%9d%e3%82%b9%e3%83%88%e3%82%bf%e3%82%a4%e3%83%97%e3%81%ae%e8%a8%98%e4%ba%8b%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%a7%e5%90%8c%e3%81%98%e3%82%bf%e3%83%bc%e3%83%a0/#post-206002)
 * すみません。上記の返信を参考に自己解決しました。
    $postを$tax_postにすればよか
   ったのですね。
 * ソース載せておきます。
 * >  <?php
   >  $custom_fields = get_post_meta( $tax_post->ID , ‘画像’ , true ); if(
   > empty( $custom_fields ) === false){ ?> <?php echo wp_get_attachment_image(get_post_meta(
   > $tax_post->ID,’画像’)); ?> <?php } ?>
 * ちなみにget_custom_img() は
    [http://www.fumufumu.info/other/973/](http://www.fumufumu.info/other/973/)
   上記の参考にした関数です。失礼しました。

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

 トピック「カスタムポストタイプの記事ページで同じタームの記事を一覧表示」には新た
に返信することはできません。

 * フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2件の返信
 * 2人の参加者
 * 最後の返信者: [k](https://ja.wordpress.org/support/users/sealight/)
 * 最後の活動: [11年、 4ヶ月前](https://ja.wordpress.org/support/topic/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%9d%e3%82%b9%e3%83%88%e3%82%bf%e3%82%a4%e3%83%97%e3%81%ae%e8%a8%98%e4%ba%8b%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%a7%e5%90%8c%e3%81%98%e3%82%bf%e3%83%bc%e3%83%a0/#post-206002)
 * 状態: 未解決

## トピック

### 人気のトピック

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

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

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

### 未解決のトピック

### すべてのトピック
