2017-08-09 70 views
0

返回0試圖實現在WordPress的自定義分頁,我不能得到職位的數量來動態創建分頁元素。計數WP_Query在WordPress的

$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.1

回答

0

您需要重置第一個查詢。因此,在第一個循環後添加此代碼並查詢

wp_reset_postdata(); 
wp_reset_query(); 

然後讓我知道結果。 感謝

0

帖子被設置爲-1。

你可以只計算Loop?

+0

循環只包含第一個X的帖子。不是所有的人。 – Tasos