Question

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?

Was it helpful?

Solution

Your code looks correct, I guess your categories are empty! Am i correct? if yes, add the following code to your last array section before 'title_li'

'hide_empty'   => 0,

So your code should be like this

$args = array(
  'taxonomy'     => $taxonomy,
  'orderby'      => $orderby,
  'show_count'   => $show_count,
  'pad_counts'   => $pad_counts,
  'hierarchical' => $hierarchical,
  'hide_empty'   => 0,
  'title_li'     => $title
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top