Wordpressを使ったサイトを作成しているのですが、Advanced Custom Fieldsで作成したカスタムフィールドで設定した画像が表示されません。
簡単に仕様の説明を致します。
「イベント開催」の記事(デフォルトの投稿記事)に担当者の名前、顔写真、所属などを書く項目があります。
複数人の担当者を選択することができ、リンク先はイベント担当者の経歴などが書いている個別の記事に飛びます。
「イベント担当者」の個別の記事はカスタム投稿タイプで実装しています。
リンク先がタクソノミーの一覧ではなく担当の人の個別記事なので、「イベント担当者」のカスタム投稿タイプを作り、カスタムフィールドで項目を追加しています。
Posts 2 Posts、Advanced Custom Fieldsの2つのプラグインを組み合わせて記事を関連づけているのですが、画像の部分がうまくいきません。
コードは以下のようにしています。
<?php $args = array( 'connected_type' => 'posts_to_pages', 'connected_items' => get_queried_object(), 'nopaging' => true, 'suppress_filters' => false ); $connected_posts = get_posts( $args ); ?> <div class="info"> <?php foreach ( $connected_posts as $post ) { setup_postdata( $post ); $photo = get_field('expert_photo'); $img = wp_get_attachment_image_src($photo, 'full'); ?> <figure class="article-circle-02"><a href="<?php the_permalink(); ?>"><img src="<?php echo $img[0]; ?>" alt="#" width="<?php echo $img[1]; ?>" height="<?php echo $img[2]; ?>"></figure> </a> <?php } wp_reset_postdata(); ?> </div> ``` var_dump($img)ではbool(false) がでます。 var_dump($photo)すると、 ``` array(10) { ["id"]=> int(2510) ["alt"]=> string(12) "test" ["title"]=> string(14) "img_experts_03" ["caption"]=> string(0) "" ["description"]=> string(0) "" ["mime_type"]=> string(10) "image/jpeg" ["url"]=> string(70) "画像のurl" ["width"]=> int(150) ["height"]=> int(150) ["sizes"]=> array(12) { ["thumbnail"]=> string(70) ""画像のurl" ["thumbnail-width"]=> int(150) ["thumbnail-height"]=> int(150) ["medium"]=> string(70) ""画像のurl" ["medium-width"]=> int(150) ["medium-height"]=> int(150) ["medium_large"]=> string(70) ""画像のurl" ["medium_large-width"]=> int(150) ["medium_large-height"]=> int(150) ["large"]=> string(70) ""画像のurl" ["large-width"]=> int(150) ``` となります。 他のページと同じようにしているつもりですが、foreach文のせいかwp_get_attachment_image_srcが機能しておらず画像が表示されません。 どのようにすれば良いでしょうか。 すみませんがご教授頂けたら幸いです。 よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/09 08:13 編集