###実現したいこと
WordPressのAdvanced Custom Fieldsの繰り返しフィールドでユーザー情報を複数出力したいです。
(プラグインなどでもっと簡単な方法があれば、教えていただけきたいです。)
###発生している問題
シングルページで
ユーザーを数人選択し表示させるため、
Advanced Custom Fieldsの繰り返しフィールドを使い、
フィールドタイプにユーザーを選択し、出力させたいと思いました。
また、同じくAdvanced Custom Fieldsを使いユーザー情報の項目も増やしました。
上記を出力するため、いろいろ調べまして、下記のコードを記述したのですが、
何も出力されない状態で、ループ内に入れることで、名前だけは出力できました。
しかし、名前も複数登録すると、全員同じ名前になります。
##カスタムフィールドに登録した項目
▼ユーザー設定画面に増やした項目:フィールド名
テキストフィールド:position
ユーザー画像:author_img (返り値:画像 配列)
▼カスタム投稿のシングルページに設定した繰り返しフィールド
フィールド名:works_author
サブフィールド:works_author_box(フィールドタイプ:ユーザー)
##コード
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if(get_field('works_author')): ?> <?php while(the_repeater_field('works_author')): ?> <figure> <?php if(get_sub_field('works_author_box')) : ?> <?php $author_id = get_the_author_meta('ID'); $author_badge = get_field('author_img', 'user_'. $author_id ); ?> <img src="<?php echo $author_badge['url']; ?>" alt="<?php echo $author_badge['alt']; ?>" /> <figcaption> <?php the_author_meta('first_name'); ?><?php the_author_meta('last_name'); ?> <span>(<?php the_author_meta('position'); ?>)</span> </figcaption> <?php endif; ?> </figure> <?php endwhile; ?> <?php endif; ?> <?php endwhile; ?><?php endif; ?>
##出力結果
<figure> <img src="" alt="" title=""> <figcaption> Firstname1Lastname1 <span>()</span> </figcaption> </figure> <figure> <img src="" alt="" title=""> <figcaption> Firstname1Lastname1 <span>()</span> </figcaption> </figure>

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/19 04:26
退会済みユーザー
2017/07/19 05:59
2017/07/19 06:55
2017/07/19 07:09
2017/07/19 07:19
2017/07/19 07:48