2014-07-23 22 views
0

當以下查詢職位:如果人觀看在簽署顯示WordPress的tax_query沒有表現出任何私人職務

$getClientsArgs = array(
    'post_type' => 'client', 
    'showposts' => -1 
); 
query_posts($getClientsArgs); 

私人職位 否則,它將跳過該職位,並繼續表現出任何非私有帖子。

這是我期望它的工作原理。

但是,當我開始使用tax_query時,私人帖子不會顯示給任何人登錄或註銷。他們根本沒有回來。

見下面的例子:

$getClientsArgs = array(
    'post_type' => 'client', 
    'showposts' => -1, 
    'tax_query' => array(
     array(
      'taxonomy' => 'client_types', 
      'field' => 'term_id', 
      'terms' => $clientType->term_id 
     ) 
    ) 
); 

query_posts($getClientsArgs); 

編輯:看來,


進一步檢查時,其上面沒有引起問題的代碼。 上線見註釋3. 其驗證碼:

<?php 
    $args = array(
     'type'   => 'client', 
     'hide_empty' => 0, //Setting this to 1 will cause the issue explained above 
     'hierarchical' => 1, 
     'taxonomy'  => 'client_types' 
    ); 

    $clientTypes = get_categories($args); 
?> 
<?php foreach ($clientTypes as $clientType): ?> 
    <h2><?php echo $clientType->name; ?></h2> 
    <div class="main clearfix"> 
     <ul class="image-list"> 
      <?php 
       $getClientsArgs = array(
        'post_type' => 'client', 
        'showposts' => -1, 
        'tax_query' => array(
         array(
          'taxonomy' => 'client_types', 
          'field' => 'term_id', 
          'terms' => $clientType->term_id 
         ) 
        ) 
       ); 

       query_posts($getClientsArgs); 
      ?> 
      <?php while (have_posts()) : the_post(); ?> 
       <li> 
        <?php $workLink = get_field('linked_project'); ?> 
        <a href="<?php echo get_permalink($workLink[0]); ?>"> 
         <img src="<?php the_field('logo'); ?>" /> 
        </a> 
       </li> 
      <?php endwhile; 
       wp_reset_query(); ?> 
     </ul> 
    </div> 
<?php endforeach; ?> 

回答

0

你需要告訴查詢,顯示私人訊息。默認情況下,只有公共帖子才能通過。

試試這個

$getClientsArgs = array(
    'post_type' => 'client', 
    'post_status' => array('publish', 'private'); 
    'showposts' => -1, 
    'tax_query' => array(
     array(
      'taxonomy' => 'client_types', 
      'field' => 'term_id', 
      'terms' => $clientType->term_id 
     ) 
    ) 
); 

query_posts($getClientsArgs); 

你也可以添加後狀態的任何其他形式。

這些都是可用的選項

publish 
pending  
draft 
auto-draft 
future 
private 
inherit 
trash 
+0

你好,請看到我的編輯。這不是造成問題的原因。 – CharliePrynn