我试图创建一个快捷码来显示自定义帖子类型以及标准帖子类别的帖子数量。我已经使用来自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\' );
以上代码仅适用于标准wordpress帖子类别,不适用于自定义帖子类型。非常感谢您的帮助。