custom post type category count shortcode
Question
I’d like to create a shortcode that would display the post count for a specific category within a custom post type. I’ve been trying to alter the code below but need some help. Could anyone let me know how to tweak so that the shortcode is for a specific custom post type.
// 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' );
Thanks in advance!
0
count, custom-post-types, posts, shortcode
6 years
2017-11-15T16:47:53-05:00
2017-11-15T16:47:53-05:00 0 Answers
85 views
0
Leave an answer