0

The following code works perfectly to show all the categories for a custom post type. However when there are no categories it echos 'No Categories'. How would I remove this?

                    <?php //Category Display for Custom Post type - Video
                    $customPostTaxonomies = get_object_taxonomies('opd-music');
                    if(count($customPostTaxonomies) > 0)
                    {

                        foreach($customPostTaxonomies as $tax)
                        {

                            $args = array(
                                'orderby' => 'name',
                                'show_count' => 0,
                                'pad_counts' => 0,
                                'hierarchical' => 1,
                                'taxonomy' => $tax,
                                'title_li' => '',
                                'echo' => 0,
                                'style' => 'simple'
                            );
                            echo '<span class="sort-button-filter">';    
                            echo  '<a href="';
                            echo $alllink;
                            echo  '">All</a>';
                            echo str_replace( '<br />', '', wp_list_categories( $args ) );
                            echo '</span>';
                             }

                    } ?>

2 Answers 2

1

I believe that what you want is show_option_none

show_option_none
(string) Set the text to show when no categories are listed. Defaults to "No categories".

http://codex.wordpress.org/Template_Tags/wp_list_categories#Parameters

Proof of concept:

$args = array('include'=>123,'show_option_none'=> '');
wp_list_categories( $args );
0

This answer is for wordpress site which have language other then english. For me, it is japanese.

The selected answer might be correct for english but its not working for Japanese site because the text for the No category is different i.e. 未分類

The default id for 'No category'/ '未分類' is 1, so we can use.

'exclude'=> '1'

POC :

$args = array('exclude'=>1);
wp_list_categories( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.