0

I am trying to use wp_dropdown_categories at front end. I got the dropdown box with default "uncategorized", the rest of the category is not there.

function cats_dropdown(){
    require_once(ABSPATH . '/wp-admin/includes/template.php');
    $args = array('taxonomy' => 'category');
?>
  <div>
     <?php wp_dropdown_categories($args); ?>
  </div>
<?php
}

In the same function, if I try to output wp_terms_checklist, it works. This is confusing. Anything I missed in the dropdown?

3 Answers 3

2

It could be that it won't show empty categories, categories that has no posts attached to them.

Try to change $args = array('taxonomy' => 'category'); to $args = array('taxonomy' => 'category', 'hide_empty' => 0);

3

By default, wp_dropdown_categories only displays the categories that have posts. Set hide_empty argument to false to display all categories, even those without posts.

$args = array(
    'taxonomy'   => 'category'
    'hide_empty' => false
);
wp_dropdown_categories($args);

On the other hand, wp_terms_checklist will display all categories, even if they are empty.

0

You shouldn't need to define the taxonomy of category as that's the default. Have you tried just using the following?

<?php $args = array('show_option_none' => 'Categories', hide_empty => '0'); ?>
<?php wp_dropdown_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.