开发者

Wordpress: force wp_tag_cloud to display empty categories?

开发者 https://www.devze.com 2023-03-11 06:18 出处:网络
I\'m using wp_tag_cloud() to display the categories in my custom taxonomy: $args = array ( \'format\'=> \'list\',

I'm using wp_tag_cloud() to display the categories in my custom taxonomy:

$args = array
(
    'format'                    => 'list',
    'orderby'                   => 'name', 
    'order'                     => 'ASC',
    'topic_count_text_callback' => default_topic_count_text,
    'link'           开发者_运维百科           => 'view', 
    'taxonomy'                  => 'my_tax', 
    'echo'                      => true 
);
    
wp_tag_cloud( $args );

The problem is that only categories with posts are displayed, so instead of seeing 40+ categories I only see 3.

Is there a way to force wp_tag_cloud to display all categories?


Some spelunking in wp_tag_cloud() (line 526 in wp-includes/category-template.php) shows that it calls get_terms() (line 1114 in wp-includes/taxonomy.php) and passes through the $args array that was passed to wp_tag_cloud(). get_terms() has a param called hide_empty that defaults to true.

This is untested, but I think if you simply add "hide_empty" => false" to your $args you'll get what you want. There may be other args to get_terms() that are of interest to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号