嗨,我想知道如何计算当前帖子的字数,我试着使用wp_get_object_terms
()和
<?php
$title = get_post($post->ID);
$numTerms = wp_count_terms( $title->post_type, array(
\'hide_empty\'=> false,
\'parent\' => 0
) ); ?>
如果运气不好,有人能解决这个问题吗?谢谢
嗨,我想知道如何计算当前帖子的字数,我试着使用wp_get_object_terms
()和
<?php
$title = get_post($post->ID);
$numTerms = wp_count_terms( $title->post_type, array(
\'hide_empty\'=> false,
\'parent\' => 0
) ); ?>
如果运气不好,有人能解决这个问题吗?谢谢
wp_count_terms
函数统计给定分类法中的术语(例如,类别总数、标记总数)。
要想得到你想要的,就要得到这个职位的条件,然后数一数count( wp_get_post_terms( $post_id, $taxonomy, $args ) );
. 或者,假设在现实生活中,您以后可能需要这些术语:
$terms = wp_get_post_terms( $post_id, $taxonomy, $args );
$terms_count = count ( $terms );
我想在中排除多个术语get_terms, 但是exclude 参数仅接受术语ID。所以我必须从它的slug中获取术语id。这就是我目前的情况:$pres = get_term_by(\'slug\', \'president\', $cat_type); $vice = get_term_by(\'slug\', \'vice-president\', $cat_type); $admin = get_term_by(\'slug\', \'admin\', $cat_type);