List all the categories with or without post

I have a simple question!

I’m showing the WP categories with this code :

Read More
wp_dropdown_categories(
    array (
        'orderby' => 'name',
        // ID of the already selected category:
        'selected' => 4,
        // If no category is selected:
        'show_option_none' => 'Choose one'
    )
);

Problem is that how can i list every category that have post or not. specially the code just shows the categories that have post , but i want to show ALL categories .

How can i change that code ?

ALso , it’s important to get the HTML output like this :

<select name='cat' id='cat' class='postform' >
    <option value='-1'>Choose one</option>
    <option class="level-0" value="4" selected="selected">Animals</option>
    <option class="level-0" value="6">Hyperbolica</option>
    <option class="level-0" value="5">Nonsense</option>
    <option class="level-0" value="1">Uncategorized</option>
</select>

Related posts

Leave a Reply

1 comment

  1. Problem is solved.

    Just need to add 'hide_empty' => false, to the array.

    Like this :

    wp_dropdown_categories(
        array (
            'orderby' => 'name',
            // ID of the already selected category:
            'selected' => 4,
            'hide_empty' => false,
            // If no category is selected:
            'show_option_none' => 'Choose one'
        )
    );