1

I have a simple question!

I'm showing the WP categories with this code :

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>
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'
    )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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