To get the custom post types you would call the get_post_types
function.The built-in public post types are post, page, and attachment. By setting ‘_builtin’ to false, we will exclude them and show only the custom public post types. Below is the code.
<?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;
?>