繁体   English   中英

使用帖子和自定义帖子类型时的WordPress分页

[英]WordPress Pagination when using posts and custom post types

我正在尝试在类别页面的末尾创建自定义分页,并且一切正常,除了我创建了自定义帖子类型,并且在发布自定义帖子时,分页总帖子数仅计算了其中的普通帖子数类别,因此您不会在分页中看到所有帖子。

我意识到它正在这里发生:

global $wp_query;
$post_count = $wp_query->found_posts;
var_dump($post_count); // number doesn't include published custom posts

我如何使wp_query-> found_posts值也包含已发布的自定义帖子,以便分页不会错过任何帖子?

$count_posts = wp_count_posts('your-post-type');
$total_posts = $count_posts->publish;
echo $total_posts . ' custom posts. ';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM