要获取自定义帖子类型,可以调用get_post_types
作用内置的公共帖子类型包括帖子、页面和附件。通过将“\\u builtin”设置为false,我们将排除它们并仅显示自定义的公共帖子类型。下面是代码。
<?php
$args = array(
\'public\' => true,
\'_builtin\' => false
);
$output = \'names\'; // names or objects, note names is the default
$operator = \'and\'; // \'and\' or \'or\'
$post_types = get_post_types( $args, $output, $operator );
foreach ( $post_types as $post_type ) {
$count_posts = wp_count_posts($post_type);
$published_posts = $published_posts+$count_posts->publish;
}
echo $published_posts;
?>