1
votes

I have the following piece of code in a WordPress site which has custom posts. This appears in a functions.php file.

It was a purchased template and I need to count the just the PUBLISHED custom posts and i added this in the code below :

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

It is working just fine at the moment, but it's counting trash as well.

Please could somebody help me, thank you very much.

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

1 Answers

0
votes

If you set hide_empty=1 in get_terms() function, Then you`ll only get terms who are assigned to any published post or custom posts.

Terms with 0 count will be ignored.