簡體   English   中英

Wordpress忽略post_per_page

[英]Wordpress ignoring post_per_page

看起來很簡單,但是我似乎無法理解正在發生的事情。

我需要將帖子數限制為25,但是我的wp_query始終返回所有記錄,並忽略posts_per_page參數。

這是我的代碼:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'posts_per_page' => 25,
    'paged' => $paged,
    'post_type' => 'noo_company',
    'industry' => $industry,
);

$the_query = new WP_Query( $args );
$posts = $the_query->posts;

這是我執行print_r($the_query)時輸出的第一部分。

WP_Query對象([查詢] =>數組([posts_per_page] => 25 [paged] => 1 [post_type] => noo_company [industry] =>咨詢)[query_vars] => Array([posts_per_page] => -1 [分頁] => 1 [post_type] => noo_company [行業] =>咨詢...

起初,按我的設置, [query] posts_per_page的值確定,但是在第二部分[query_vars]其重置為'-1' ,我不知道為什么會發生這種情況。

在此先感謝您提供任何有用的建議。

該代碼對我有用,並且希望對您有用,只需復制並粘貼代碼,然后將插件名稱安裝為“ wp_pagenavi”即可進行頁面分頁。

if ( have_posts() ) : 
`enter code here`$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  $query_args = array(
    'post_type' => 'noo_company',
    'posts_per_page' => 5,
    'paged' => $paged
  );
// create a new instance of WP_Query
$the_query = new WP_Query( $query_args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop 
the_title();
endwhile;
if ($the_query->max_num_pages > 1) { 
if(function_exists('wp_pagenavi')) { wp_pagenavi();} 
} 
else: 
_e('Sorry, no posts matched your criteria.'); 
endif;  
endif;

我刪除了post_type參數,現在一切正常,可能是特定於主題的,我不知道到底是什么引起了問題,但是無論如何現在都已解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM