I am trying to create a shortcode to display the posts count of a custom post type as well as standard post categories. I have successfully done this using this code snippet from a similar post:
// Add Shortcode to show posts count inside a category
function category_post_count( $atts ) {
$atts = shortcode_atts( array(
'category' => null
), $atts );
// get the category by slug.
$term = get_term_by( 'slug', $atts['category'], 'category');
return ( isset( $term->count ) ) ? $term->count : 0;
}
add_shortcode( 'category_post_count', 'category_post_count' );
The code above only works for standard wordpress post categories, not custom post types. Any help is appreciated.