2016-06-14 84 views
1

在WordPress是新手參考下面我的編碼,它沒有得到所有記錄:如何在wordpress中使用where條件獲取所有行?

post_author ='1' and post_type ='attachment' 

這只是僅返回單行。在我的數據庫中有20行,其中:

post_author ='1' and post_type ='attachment' 

這是我的PHP代碼:

<?php 
    $args = array('author' => '1' ,'post_type' => 'attachment'); 
    $query = new WP_Query($args); 
    if ($query->have_posts()) { 
     while ($query->have_posts()) { 
      $query->the_post(); 

      // now $query->post is WP_Post Object, use: 
      echo $query->post->ID; 
     } 
    } 
?> 

回答

0

試試下面的代碼

使用custom query

$user_id = 1; 
$the_query = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'inherit', 'author' => $user_id)); 
if ($the_query->have_posts()) while ($the_query->have_posts()) : $the_query->the_post(); 
    the_title(); 
endwhile; 
+0

沒有它也返回單行。 –

+0

我已經更新了我的答案,請你檢查一下嗎? – purvik7373

+0

是的,檢查,但沒有記錄獲得上述代碼? –

相關問題