gpt4 book ai didi

wordpress - WP_Query 计数帖子 - 自定义帖子类型

转载 作者:行者123 更新时间:2023-12-02 08:10:15 24 4
gpt4 key购买 nike

我如何从自定义帖子类型中计算条目?

<ul class="test">
<?php $args = array( 'post_type' => 'schusslersalz', 'posts_per_page' => 30, 'orderby' => 'rand' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<li>';
the_title('<h3>', '</h3>');
the_content();
echo '</li>';
endwhile; ?>
</ul>

我如何计算“schusslersalz”中的条目并显示它。
我已经搜索并找到了功能:
$count = $loop->post_count;

我怎么用这个?

最佳答案

wp_count_posts函数有参数 $type要统计帖子类型,如果要统计schusslersalz 的数量,应使用此参数。

一个片段

$count_posts = wp_count_posts( 'schusslersalz' )->publish;
echo $count_posts;

完整片段如下:
$args = array(
'post_type' => 'schusslersalz'
);
$the_query = new WP_Query( $args );
echo $the_query->found_posts;

希望我有所帮助

关于wordpress - WP_Query 计数帖子 - 自定义帖子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47941628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com