我想从 Wordpress 数据库中选择内容来填充所有不同类别的 <select> ,但有可能 2 个或更多帖子具有相同的类别,在这种情况下,我应该只显示一次该类别。
一个例子:
Post1 cat = EN
Post2 cat = EN
Post3 cat = DE
Post4 cat = FR
Post5 cat = FR
// The Result sould look like this:
EN
DE
FR
这是代码的当前状态:(但效果不佳)
<select name="sprache">
<option value="0">Alle Sprachen</option>
<?php
$selectsql = "
SELECT
wpos ts.*,
wterms.*
FROM $wpdb->posts wposts
INNER JOIN $wpdb->term_relationships AS tr ON (wposts.ID = tr.object_id)
INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms wterms ON (tt.term_id = wterms.term_id)
INNER JOIN $wpdb->postmeta wpostmeta ON (wposts.ID = wpostmeta.post_id)
WHERE wposts.post_status = 'publish'
AND tt.taxonomy = 'th5'
AND wpostmeta.meta_key= '_sprachgruppen'
GROUP BY tt.taxonomy
";
$select_output = $wpdb->get_results($selectsql,OBJECT);
if ($select_output){
foreach ($select_output as $post){
setup_postdata($post);
if(isset($_POST[gruppe])){
$option .= '<option value="'.$post->term_id.'"';
$option .= ' >';
$option .= $post->name;
$option .= '</option>';
}
echo $option;