2013-08-03 45 views
0

好吧,我已正確顯示所有內容,但是如果在自定義字段"item_tags"的字段'value'內沒有條件術語'Non-Marine'以外的術語,則不會顯示這些術語。僅在字符串或數組中顯示具有特定自定義字段值的帖子

基本上我尋找一個帖子:
1.定製post_type - AIT-DIR-項目
2.自定義場位置 - 安納波利斯
3.自定義場item_tags - 非海洋(這個值是用逗號隔開的其他術語)

我也不確定這些值是字符串還是數組?

這裏是我到目前爲止的代碼:

<?php 
$args = array('post_type' => 'ait-dir-item', 
       'meta_query' => array(
        array(
         'key' => 'location', 
         'value' => 'annapolis' 
        ), 
        array(
         'key' => 'item_tags', 
         'value' => 'non-marine' 
        ) 
       ), 
       'orderby' => 'title', 
       'order' => 'ASC', 
       'posts_per_page' => 300); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); 
    the_title('<h3 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></h3>'); 
    echo '<div class="entry-content">'; 
    the_content(); 
    echo '</div>'; 
endwhile; 
?> 

感謝任何投入!

Cory-

+0

我認爲這是一個與WordPress如何構建查詢有關的問題,請添加必要的標籤以反映這一點。 – NDM

回答

0

有沒有你誤認爲是自定義字段標籤的機會 - 「這是逗號分隔的自定義字段item_tags」 ......聽起來像一個標籤給我。對不起,如果我錯了。

在這種情況下,它的一部分是這樣的:

'tax_query' => array(
    array(
     'taxonomy' => 'item_tags', 
     'field' => 'slug', 
     'terms' => 'non-marine' 
    ) 
) 

整個事情是這樣的:

<?php 
$args = array('post_type' => 'ait-dir-item', 
    'meta_query' => array(
     array(
      'key' => 'location', 
      'value' => 'annapolis' 
     ), 
    ), 
    'tax_query' => array(
     array(
      'taxonomy' => 'item_tags', 
      'field' => 'slug', 
      'terms' => 'non-marine' 
     ) 
    ) 

    'orderby' => 'title', 
    'order' => 'ASC', ... etc 

如果你想逗號分隔標籤,你確實應該反正使用custom taxonomies (codex here)

相關問題