ユーザー情報を固定ページで表示することについて質問です。
【前提】
- サイトで、会員(ユーザー)を地域別に振り分けたリストを出力したい。
- 会員にWPのアカウントを与え、ユーザーのプロフィール編集ページで入力した値を上記ページに反映する。
- Advanced Custom Fieldで、プロフィール編集ページに、地域のSelectフィールドを追加し、会員に選択してもらう。フィールド名は「user_address1」。
※ Selectフィールドの選択肢は例として以下の通り、値とラベルで設定
data1 : 〇〇市
data2 : □□市
data3 : △△市
data4 : △△市
[実現したいこと]
選択した値を元に、組合員の紹介ページに地域別に振り分けて一覧で表示したい。
現状作成したコードは以下になります。
組合員の一覧が表示されます。
<div class="js-scrollable scroll-hint is-scrollable" style="position: relative;overflow: auto;"> <table class="tabledata"> <?php $users = get_users( array( 'exclude' => array(1,2)) ); ?> <tr><th>商号</th><th>代表者</th><th>住所</th><th>TEL</th><th>詳細</th></tr> <?php foreach($users as $user) { $uid = $user->ID; ?> <tr> <td class="data_name"><a href="<?php echo get_bloginfo("url") . '/?author=' . $uid ?>"><?php echo $user->last_name ; ?></a></td> <td><?php the_field('user_name', $user); ?></td> <td><?php the_field('user_address2', $user); ?></td> <td><?php the_field('user_tel', $user); ?></td> <td><a class="icon_link" href="<?php echo get_bloginfo("url") . '/?author=' . $uid ?>"><i class="icon-school"></i></a></td> <?php }; ?> </tr> </table> </div><!--scroll-hint-->
【やってみたこと】
同じようなことをやっているサイトを参考に、見よう見まねでやってみましたがうまくいきません。
地域を選択しても「現在、組合員の追加はありません。」と表示されます。
<?php $users = []; $page_dep = get_field( 'user_address1' ); if ( $page_dep ) { $users = get_users( array( 'orderby' => 'ID', 'order' => 'ASC', 'meta_key' => 'user_address1', 'exclude' => array(1,2), 'meta_value' => $page_dep ) ); } ?> <?php if ( $users ) { ?> <?php foreach ( $users as $user ) {$uid = $user->ID; ?> <div class="js-scrollable scroll-hint is-scrollable" style="position: relative;overflow: auto;"> <table class="tabledata"> <tr><th>商号</th><th>代表者</th><th>住所</th><th>TEL</th><th>詳細</th></tr> <tr> <td class="data_name"><a href="<?php echo get_bloginfo("url") . '/?author=' . $uid ?>"><?php echo $user->last_name ; ?></a></td> <td><?php the_field('user_name', $user); ?></td> <td><?php the_field('user_address2', $user); ?></td> <td><?php the_field('user_tel', $user); ?></td> <td><a class="icon_link" href="<?php echo get_bloginfo("url") . '/?author=' . $uid ?>"><i class="icon-school"></i></a></td> </tr> </table> </div><!--scroll-hint--> <?php } ?> <?php } else { ?> <p>現在、組合員の追加はありません。</p> <?php } ?>
お詳しい方、何卒ご教授お願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/11/10 07:09