计算Wordpress中发布的自定义帖子

时间:2014-01-13 10:05:11

标签: php wordpress

我在WordPress网站上有以下代码,其中包含自定义帖子。 它出现在functions.php文件中。

这是一个购买的模板,我需要计算PUBLISHED自定义帖子,我在下面的代码中添加了这个:

'.'('.$option->count.')'.' 

目前工作正常,但它也在计算垃圾。

请有人帮助我,非常感谢你。

function dox_get_list_terms( $taxonomy = 'category', $term_id, $number, $orderby = 'name', $order = 'ASC', $hide = '0' ) {          
        $terms = array();
        $terms = explode(',', $term_id);
        $count = count( $terms );

        $output = '';       
        foreach( $terms as $term ) {
            if ($term >= 0) {
                $options = get_terms( $taxonomy,  'number='.$number.'child_of='.$term.'&parent='.$term.'&hide_empty='.$hide.'&hierarchical=1&depth=1&orderby='.$orderby.'&order='.$order );

                if (! is_wp_error($options) ) {
                    foreach ($options as $option) {
                        $output .= '<li>
                        <a href="'.get_term_link($option->slug, $taxonomy).'">
                        '.$option->name.'
                         </a>
                         '.'('.$option->count.')'.'                              
                        </li>'; 


                    }
                }
            }
        }

        return $output;         
}

1 个答案:

答案 0 :(得分:0)

如果您在hide_empty=1功能中设置get_terms(),则您只会获得分配到任何已发布帖子或自定义帖子的字词。

0计数的术语将被忽略。