1

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

When I add the following content to functions.php

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

  • Could you clarify what that means? I don't quite understand you. Thanks. – Julia Mar 28 '14 at 14:26
  • Tried that and it's not working for me. I have have Post Name option selected, btw. – Julia Mar 28 '14 at 14:30
  • Do you have seen this q&a with a solid solutiuon? – bueltge Mar 28 '14 at 14:52
  • Please move solution you discovered to an answer, that is more proper than edit and question won't haunt site as unanswered. :) – Rarst Mar 28 '14 at 18:17
  • I can't. I just joined the site and I get the warning "Users with less than 10 reputation can't answer their own question for 8 hours after asking" lol – Julia Mar 28 '14 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.