Widget Categories shows “No categories”

Widget on the front-end

I have a custom post type called “News” which looks like this:

/**
 * Register "News" custom post type
 */
function news_custom_post_type() {

    $labels = array(
        'name'                  => _x( 'News', 'Post Type General Name', 'school' ),
        'singular_name'         => _x( 'News Item', 'Post Type Singular Name', 'school' ),
        'menu_name'             => __( 'News', 'school' ),
        'name_admin_bar'        => __( 'News', 'school' ),
        'archives'              => __( 'News Archives', 'school' ),
        'attributes'            => __( 'News Attributes', 'school' ),
        'parent_item_colon'     => __( 'Parent Post:', 'school' ),
        'all_items'             => __( 'All Posts', 'school' ),
        'add_new_item'          => __( 'Add a New Post', 'school' ),
        'add_new'               => __( 'Add New', 'school' ),
        'new_item'              => __( 'New Post', 'school' ),
        'edit_item'             => __( 'Edit Post', 'school' ),
        'update_item'           => __( 'Update Post', 'school' ),
        'view_item'             => __( 'View Post', 'school' ),
        'view_items'            => __( 'View Posts', 'school' ),
        'search_items'          => __( 'Search Posts', 'school' ),
        'not_found'             => __( 'Not found', 'school' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'school' ),
        'featured_image'        => __( 'Featured Image', 'school' ),
        'set_featured_image'    => __( 'Set featured image', 'school' ),
        'remove_featured_image' => __( 'Remove featured image', 'school' ),
        'use_featured_image'    => __( 'Use as featured image', 'school' ),
        'insert_into_item'      => __( 'Insert into post', 'school' ),
        'uploaded_to_this_item' => __( 'Uploaded to this post', 'school' ),
        'items_list'            => __( 'Posts list', 'school' ),
        'items_list_navigation' => __( 'Posts list navigation', 'school' ),
        'filter_items_list'     => __( 'Filter posts list', 'school' ),
    );
    $args = array(
        'label'                 => __( 'News Post', 'school' ),
        'description'           => __( 'A custom post type for news posts.', 'school' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'excerpt' ),
        'taxonomies'            => array( 'news' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'news', $args );

}
add_action( 'init', 'news_custom_post_type', 0 );

I’ve also set up taxonomies for this post type:

/**
 * Register "News" Categories
 */
function news_categories() {

    $labels = array(
        'name'                       => _x( 'Categories', 'Taxonomy General Name', 'school' ),
        'singular_name'              => _x( 'Category', 'Taxonomy Singular Name', 'school' ),
        'menu_name'                  => __( 'Categories', 'school' ),
        'all_items'                  => __( 'All Items', 'school' ),
        'parent_item'                => __( 'Parent Category', 'school' ),
        'parent_item_colon'          => __( 'Parent Category:', 'school' ),
        'new_item_name'              => __( 'New Category Name', 'school' ),
        'add_new_item'               => __( 'Add New Category', 'school' ),
        'edit_item'                  => __( 'Edit Category', 'school' ),
        'update_item'                => __( 'Update Category', 'school' ),
        'view_item'                  => __( 'View Category', 'school' ),
        'separate_items_with_commas' => __( 'Separate categories with commas', 'school' ),
        'add_or_remove_items'        => __( 'Add or remove categories', 'school' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'school' ),
        'popular_items'              => __( 'Popular Categories', 'school' ),
        'search_items'               => __( 'Search Categories', 'school' ),
        'not_found'                  => __( 'Not Found', 'school' ),
        'no_terms'                   => __( 'No items', 'school' ),
        'items_list'                 => __( 'Categories list', 'school' ),
        'items_list_navigation'      => __( 'Categories list navigation', 'school' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'news', array( 'news' ), $args );

}
add_action( 'init', 'news_categories', 0 );

I’ve added my categories via WP Admin and the created three posts with those categories assigned.

Via widgets, I’ve added the “Categories” widget. When you visit the News archive page, the widget says “No Categories”.

Any ideas?

Read more here:: Widget Categories shows “No categories”

Leave a Reply

Your email address will not be published. Required fields are marked *