Custom taxonomy for Media Library

I am trying to create a custom taxonomy for the Media Library called “Reference Type”

When I add the following content to functions.php

Read More
function wptp_add_reference_type_taxonomy() {
    $labels = array(
        'name'              => 'Add Reference Type',
        'singular_name'     => 'Reference Type',
        'search_items'      => 'Search Reference Type',
        'all_items'         => 'All Reference Type',
        'parent_item'       => 'Parent Reference Type',
        'parent_item_colon' => 'Parent Reference Type:',
        'edit_item'         => 'Edit Reference Type',
        'update_item'       => 'Update Reference Type',
        'add_new_item'      => 'Add New Reference Type',
        'new_item_name'     => 'New Reference Type',
        'menu_name'         => 'Reference Type',
    );

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

    register_taxonomy( 'reference_type', 'attachment', $args );
}
add_action( 'init', 'wptp_add_reference_type_taxonomy' );

Options to add and modify items in that taxonomy show in the admin panel.

However, when I got a page like http://sitehere.com/reference_type/sample-item
I get redirected to a Page Not Found in index.php and not the custom page I have set up for this taxonomy in taxonomy.php

In addition, when I add a reference type “sample item” to a media item it will show up in the Library tab, but in the Reference Type tab, it will say there are 0 items under “sample item”.

In general, when i try to print a list of items in this taxonomy it does not show up (I am using code suggested in the WP codex).

SOLUTION

Adding 'rewrite' => array('slug' => 'reference_type', 'with_front' => false) fixed my issue of not being able to view individual item pages.

Adding 'update_count_callback' => '_update_generic_term_count' fixes my issue with the count not updating

Related posts

Leave a Reply