WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get all categories in a new page which doesn't include any post. I tried wp_list_categories(); function. But it show only "No category" message. How do I do it?

share|improve this question

migrated from stackoverflow.com Feb 24 '11 at 23:08

This question came from our site for professional and enthusiast programmers.

There's an entire (wonderful!) site for these questions: wordpress.stackexchange.com – editor Feb 24 '11 at 21:45

This will only display the categories if there are posts associated with them, make sure that there are posts in your WordPress database. However, you might try:


which will override that functionality.

share|improve this answer

This code will show and unordered list with the name of the category and the count the total posts containing.

<ul class="myClass">
 <?php $categories = get_categories(array('hide_empty'=>0,'number=100'));
       foreach ($categories as $cat) {
       echo "<li>". $cat->cat_name . " - ". $cat->category_count ." posts.</li>";
       } ?>

Retrieves the 100 first categories (you can change the 100 for any number you want)

$categories = get_categories(array('hide_empty'=>0,'number=100'));

and for each of them (even the empty ones) shows cat_name and category_count

Copy the code above in the page file you want to dispay the result.

You will get some like this:

  • PHP - 0 posts.
  • Uncategorized - 4 posts.
  • WordPress - 1 posts.

I hope that could help you.

ps: If you need them as links, replace the line

 echo "<li>". $cat->cat_name . " - ". $cat->category_count ." posts.</li>";


echo '<li><a href="'.get_category_link($cat->cat_ID).'">'. $cat->cat_name . '</a> - '. $cat->category_count .' posts.</li>';
share|improve this answer

You can use

<?php $categories = get_categories( $args ); ?> 


$args = array(
    'type'                     => 'post',
    'child_of'                 => 0,
    'parent'                   => '',
    'orderby'                  => 'name',
    'order'                    => 'ASC',
    'hide_empty'               => 1,
    'hierarchical'             => 1,
    'exclude'                  => '',
    'include'                  => '',
    'number'                   => '',
    'taxonomy'                 => 'category',
    'pad_counts'               => false 



also read about more details on this link


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.