1

I have a custom taxonomy which I want to appear under a custom menu. And I achieved that by specifying the custom menu as the parent. Here's the result:

However, when I click on it, the CSV Tag Upload menu collapses, and the taxonomy opens itself under the Posts menu:

enter image description here

Any idea why this happens and how I can fix it? I've been having this problem for a long time now, but it's becoming a problem now.

EDIT: Code for registering taxonomy:

function csv_tags_taxonomy() {

    $labels = array(
        'name' => _x( 'CSV Tags', 'taxonomy general name' ),
        'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Tags' ),
        'popular_items' => __( 'Popular Tags' ),
        'all_items' => __( 'All Tags' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edit Tag' ), 
        'update_item' => __( 'Update Tag' ),
        'add_new_item' => __( 'Add New Tag' ),
        'new_item_name' => __( 'New Tag Name' ),
        'separate_items_with_commas' => __( 'Separate tags with commas' ),
        'add_or_remove_items' => __( 'Add or remove tags' ),
        'choose_from_most_used' => __( 'Choose from the most used tags' ),
        'menu_name' => __( 'CSV Tags' ),
        ); 

    register_taxonomy('csv_tags','post',array(
        'hierarchical' => false,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var' => true,
        'rewrite' => array( 'slug' => 'csv-tags' ),
        ));
}
add_action('init', 'csv_tags_taxonomy');
5
  • Please, show us the code you are using to register the custom taxonomy.
    – cybmeta
    Commented Feb 11, 2015 at 17:34
  • I edited the original post. Commented Feb 12, 2015 at 15:51
  • Note the second parameter of register_taxonomy function, you have registered the taxonomy for posts, that is why it appears under Posts menu.
    – cybmeta
    Commented Feb 12, 2015 at 16:38
  • I wish it were that easy :D the second parameter of register_taxonomy refers to the post type to which the taxonomy is tied. This taxonomy is tied to posts, but I don't really use it for posts, I use it for something else. I guess the only way to do this is to incorporate iframes or something. Commented Feb 12, 2015 at 20:56
  • Oh, yes, it is that easy, if you associate a taxonomy and a post type, they are associated, if you don't associate them, they are nost associated. See my answer.
    – cybmeta
    Commented Feb 12, 2015 at 23:27

2 Answers 2

0

I had the same problem even though my taxonomy was registered to Users. Found the answer at Custom user taxonomies in WordPress by Justin Tadlock (see the comments for the post).

Add this to your code (replace YOUR_TAXONOMY with the proper name):

function fix_user_tax_page( $parent_file = '' ) {
    global $pagenow;

    if ( ! empty( $_GET[ 'taxonomy' ] ) && $_GET[ 'taxonomy' ] == 'YOUR_TAXONOMY' && $pagenow == 'edit-tags.php' ) {
    $parent_file = 'users.php';
    }

  return $parent_file;
}

EDIT: OK, it works just fine the first time, but I have two custom taxonomies, and I can't get it to work for the second one (everything within the same functions.php file in the child theme). I changed the taxonomy name, the function name, and the global variable name.

Anyone have any ideas?

EDIT:

First of all, the above code was missing a line. The whole thing should be:

add_filter( 'parent_file', 'fix_user_tax_page' );

function fix_user_tax_page( $parent_file = '' ) {
        global $pagenow;

    if ( ! empty( $_GET[ 'taxonomy' ] ) && $_GET[ 'taxonomy' ] == 'YOUR_TAXONOMY' && $pagenow == 'edit-tags.php' ) {
        $parent_file = 'users.php';
    }

    return $parent_file;
}

Second thing, I just found the answer about using this for more than one custom taxonomy: remove the && $_GET[ 'taxonomy' ] == 'YOUR_TAXONOMY'.

1
  • Yeah, but the custom menu uses admin.php as the parent file. However, when I put admin.php, then no menu is selected. Any ideas why that's so? Commented Feb 13, 2015 at 15:47
0

Your problem is that you are associating a taxonomy and a post type but you don't that associtaion. If you don't want a taxonomy be associated with Posts (standard post type), don't associate them, it is that easy. If you need a taxonomy with no post type associated, set $object_type to null (see codex):

function csv_tags_taxonomy() {

    $labels = array(
        'name' => _x( 'CSV Tags', 'taxonomy general name' ),
        'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Tags' ),
        'popular_items' => __( 'Popular Tags' ),
        'all_items' => __( 'All Tags' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edit Tag' ), 
        'update_item' => __( 'Update Tag' ),
        'add_new_item' => __( 'Add New Tag' ),
        'new_item_name' => __( 'New Tag Name' ),
        'separate_items_with_commas' => __( 'Separate tags with commas' ),
        'add_or_remove_items' => __( 'Add or remove tags' ),
        'choose_from_most_used' => __( 'Choose from the most used tags' ),
        'menu_name' => __( 'CSV Tags' ),
        ); 

    register_taxonomy('csv_tags', null, array(
        'hierarchical' => false,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var' => true,
        'rewrite' => array( 'slug' => 'csv-tags' ),
        ));
}
add_action('init', 'csv_tags_taxonomy');
3
  • Hey thanks a lot for this. It doesn't exactly solve my problem, but I didn't know up until your post that I can leave the post type blank. Commented Feb 13, 2015 at 15:47
  • I thought I understood your problem, but it seems not. Can you explain?
    – cybmeta
    Commented Feb 13, 2015 at 15:52
  • See the post below. Commented Feb 13, 2015 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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