2017-08-09 69 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