Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I just registered following code in my function

add_action( 'init', 'create_resources_taxonomies', 0 );

function create_resources_taxonomies() {
    $labels = array(
        'name'              => _x( 'cat2', 'taxonomy general name' ),
        'singular_name'     => _x( 'cat2', 'taxonomy singular name' ),
        'search_items'      => __( 'Search category' ),
        'all_items'         => __( 'All category' ),
        'parent_item'       => __( 'Parent category' ),
        'parent_item_colon' => __( 'Parent category:' ),
        'edit_item'         => __( 'Edit category' ),
        'update_item'       => __( 'Update Category' ),
        'add_new_item'      => __( 'Add New Category' ),
        'new_item_name'     => __( 'New category Name' ),
        'menu_name'         => __( 'genre' ),
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'genre' ),
    );

    register_taxonomy( 'genre', array( 'resources' ), $args );
}

and i want to get category list in my sidebar, so i added following code in my sidebar

<?php    
$taxonomy     = 'genre';
$orderby      = 'name'; 
$show_count   = 0;      // 1 for yes, 0 for no
$pad_counts   = 0;      // 1 for yes, 0 for no
$hierarchical = 1;      // 1 for yes, 0 for no
$title        = '';

$args = array(
  'taxonomy'     => $taxonomy,
  'orderby'      => $orderby,
  'show_count'   => $show_count,
  'pad_counts'   => $pad_counts,
  'hierarchical' => $hierarchical,
  'title_li'     => $title
);
?>

<ul>
<?php wp_list_categories( $args ); ?>
</ul>

But i just get "No categories" text. What is wrong with my code?

share|improve this question

1 Answer 1

on the $args (used on your sidebar file), add another parameter - 'hide_empty' => false. Using wp_list_categories() doesn't not display terms which doesn't have at least one post type object assigned with it. 'hide_empty' => false force it to display all of the terms.

share|improve this answer
    
which $args? And btw not sure it will solve the problem. –  Mark Kaplun Feb 12 at 6:00
    
Thank you. I updated the answer. This is the only thing i could guess checking the codes in the question. As like you, i am not sure either, but don't u think this could solve the problem if the problem is terms were only created but was not assigned to any resources ? –  Shazzad Feb 12 at 6:31
    
yes, but maybe better to ask in the comments first, maybe there are no categories defined at all.... (unlikely I know) –  Mark Kaplun Feb 12 at 6:39

Your Answer

 
discard

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

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