会員サイトで、会員リストを住所で並べ替える場合
- 投稿タイトル:会員名
- カスタムフィールドの名前(key)を「住所」として、カスタムフィールドの値に会員の住所を入れる。
例えば「西宮市××町×××」(住所をカスタムフィールドの値にするのは、便宜的な意味だけです) - カスタムフィールドの名前(key)を「ふりがな」として、カスタムフィールの値を、「にしのみやし」
他にも、電話番号とか・・・
category.phpに下記のコードを書く(posts_per_page=30/1ページに30の投稿をリスト)
<?php global $wp_query;?> <?php query_posts('&cat='.$cat.'&orderby=meta_value&meta_key=ふりがな&order=ASC&posts_per_page=30&paged='.$paged); ?> <table> <tr> <th>会員名/th> <th>住所</th> </tr> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <tr> <td><?php the_title(); ?></td> <td><?php echo post_custom('住所'); ?></td> </tr> <?php endwhile; endif; ?> </table> <?php wp_reset_query(); ?>
カスタムフィールドを利用してもっといろいろな出力ができます。
参考サイト:「小粋空間」WordPressでカスタムフィールドを出力する方法のまとめ