WordPress – Post Count Shortcode
This function creates a shortcode that shows a post count for published posts within a specific custom post type. To use for a different post type just change the name of the post type from “movie” to your custom post type’s name in the function below. Then rename the shortcode within the function to correspond to that custom post type.
To use the function as a standard WordPress shortcode add the following to your site:
[postcount-movie]
To hardcode this function into your theme use the following PHP script:
<?php echo do_shortcode("[postcount-movie]"); ?>
To enable this function you need to add the following to your WordPress theme’s functions.php file.
function post_count() {
$count_posts = wp_count_posts('movie');
$published_posts = $count_posts->publish;
return $published_posts . ' ';
}
add_shortcode('postcount-movie', 'post_count');

Leave a Reply
Want to join the discussion?Feel free to contribute!