私はディレクトリのスタッフリストに取り組んでいます。この目的のためのプラグインは、私が探していたものにはあまりにも複雑すぎたり、シンプルすぎたりしたので、私はカスタムソリューションに行きました。 私はこのカスタムポストタイプ "staff"を作成してカスタム分類を付けて(Science、Mathematics、Administrationなど)作成しましたので、テーブルにリストされたすべての投稿を取得するクエリがあります。カスタムフィールドの最初の文字によるクエリのフィルタリング - Wordpress
<table class="directorytable">
<thead>
<th class="first-th">Portrait</th>
<th>Name</th>
<th>Position</th>
<th>Phone</th>
<th style="width:60px !important;text-align:center;">Email </th>
<th style="width:60px !important;text-align:center;">Website </th>
<th style="width:60px !important;text-align:center;">Details </th>
</thead>
<?php query_posts(array('post_type'=>'staff','orderby'=>'meta_value','meta_key'=>'staff_last_name','order'=>'asc'))?>
<?php while(have_posts()): the_post();?>
<tr>
<td class="first-td"><a rel="lightbox" href="<?php the_permalink(); ?>"/><img src="<?php the_field('staff_portrait');?>" style="border-radius:2px; width:35px;"/></a></td>
<td><a rel="lightbox[1]" href="<?php the_permalink();?>"><?php the_field('staff_name');?> <?php the_field('staff_last_name');?></a> </td>
<td><?php the_field('staff_position'); ?></td>
<td><?php the_field('staff_phone');?> | <strong>Ext: </strong><?php the_field('staff_extension')?></td>
<td style="width:60px; text-align:center;"><a href="mailto:<?php the_field('staff_email');?>"><img src="/images/directory/mail.png"/></a></td>
<td style="width:60px; text-align:center;"><?php if(get_post_meta($post->ID,'staff_website', true)){?><a target="_blank" href="<?php the_field('staff_website');?>"><img src="/images/directory/document-globe.png"/></a><?php } else {?><?php echo '';?><?php } ?></td>
<td style="width:60px; text-align:center;"><a rel="lightbox[2]" href="<?php the_permalink();?>"><img src="/images/directory/magnifier-zoom.png"/></a></td>
</tr>
<?php endwhile; ?>
</table>
このリストは非常にうまく機能していますが、クライアントからアルファベットインデックスを追加するように依頼されました。結果が出る前にリストされた範囲が必要になり、クリックすると、 "staff_last_name"カスタムフィールド(私はACFを使用しています)が選択された文字で始まる投稿のみが表示されます。
私はAZIndex、WP-Snapなどのプラグインで試してみましたが、私のために働いたものはありませんでした。
私はこの問題について推奨/解決を感謝したいと思います。
こんにちはホボ、すごくお世話してくれてありがとうございました...悲しいことに私はそれを100%理解できないと言わなければなりません。私はyeyがテーブルの上に示したいインデックスA-Zを生成しなかった。あなたの説明の背後にある考え方は、文字が押されたときに新しいクエリを生成することです。私は正直言って、これをどう扱うかという考えは一切ないので、私は何も定義しなかった。申し訳ありません、もう一度、ありがとうございます。 – Jaypee
BETWEENを使って、検索された文字を引っ張り、次の値のためにそれを増やした配列を作成して、メタフィールドの最初の文字で「投稿」を完全に検索しました。ありがとう – philhoyt