2017-08-09 7 views
0

Wordpressでカスタムページネーションを実装しようとしましたが、ページング数を取得してページング要素を動的に作成できません。Count WP_QueryがWordpressで0を返します

$loop = new WP_Query(
      array(
       'post_type'   => 'product', 
       'post_status '  => 'publish', 
       'orderby'   => 'post_date', 
       'order'    => 'date', 
       'posts_per_page' => $per_page, 
       'offset'   => $start, 
       'tax_query' => array( 
        array(
         'taxonomy' => 'product_cat', 
         'field' => 'id', 
         'terms' => $suv_cates 
        ) 
       ) 

      ) 
     ); 

$count = new WP_Query(
      array(
       'post_type'   => 'product', 
       'post_status '  => 'publish', 
       'posts_per_page' => -1, 
       'tax_query' => array( 
        array(
         'taxonomy' => 'product_cat', 
         'field' => 'id', 
         'terms' => $suv_cates 
        ) 
       ) 
      ) 


); 

return $count->post_count; 

$loopの最初のクエリは、必要な投稿を返します。しかし、$countまたは$count->post_countを返すと0が返されます。

答えて

0

最初のクエリをリセットする必要があります。最初のループとクエリの後にこのコードを追加してください。

wp_reset_postdata(); 
wp_reset_query(); 

次に結果をお知らせください。 ありがとう

0

1ページあたりの投稿数は-1に設定されています。

Loopを数えてもいいですか?

+0

ループには最初のx個の投稿のみが含まれています。それらのすべてではありません。 – Tasos

関連する問題