2015-03-19 138 views
-1

自定義帖子是一個商店。每個城市都有很少的商店。 我需要顯示在自定義帖子中從自定義字段中獲取的城市列表,但我想刪除重複項。任何幫助都會很棒。如何從Wordpress查詢中刪除自定義字段重複

$the_query = new WP_Query( 
array(
'numberposts' => -1, 
'post_type' => 'store', 
'meta_key' => 'city', 
'orderby'   => 'meta_value', 
'order'   => 'ASC', 
) 
); 
if ($the_query->have_posts()) { 
echo '<ul>'; 
while ($the_query->have_posts()) { 
    $the_query->the_post(); 
    echo '<li>' . get_field('city' ) . '</li>'; 
} 
echo '</ul>'; 
} else { 

} 
wp_reset_postdata(); 

回答

0

如果您使用城市的自定義分類標準,wordpress有稅收查詢可以過濾它們會容易得多。

+0

我是新來的。這是顯而易見的,但除了我以外的所有:) – Bla 2015-03-19 12:48:21

+0

好專家也是新手一次:) – 2015-03-19 12:51:33