【问题标题】:WordPress Pagination when using posts and custom post types使用帖子和自定义帖子类型时的 WordPress 分页
【发布时间】:2014-02-28 19:26:49
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: php wordpress pagination


    【解决方案1】:
    $count_posts = wp_count_posts('your-post-type');
    $total_posts = $count_posts->publish;
    echo $total_posts . ' custom posts. ';
    

    【讨论】:

    • 为您的答案提供一些描述
    猜你喜欢
    • 2014-05-15
    • 2011-03-20
    • 2014-05-21
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 2013-06-22
    相关资源
    最近更新 更多