• Resolved Colin M Tomele

    (@maniacalv)


    Hi all! I’m trying to get my head around something and could use a little advice.

    I have a custom post type for a “lending”, using meta_box to get info and adding you to a waiting list for an item.

    I have custom taxonomies for location and item type.

    I am creating a new post type to manage the actual items that will be lent out.

    I have shared a taxonomy between them.

    How do I hide the admin links for managing the taxonomy from one of the custom post types?

     register_taxonomy(  'lendingq_location', 
                                    array( 'lendingq_hold', 'lendingq_stock' ), 
                                    array(
                                        'labels'                         => array(
                                            'add_new_item'               => __( 'Add New Location', 'text_domain' ),
                                            'add_or_remove_items'        => __( 'Add or remove items', 'text_domain' ),
                                            'all_items'                  => __( 'All Locations', 'text_domain' ),
                                            'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
                                            'edit_item'                  => __( 'Edit Location', 'text_domain' ),
                                            'edit_item'                  => __( 'Edit Location', 'text_domain' ),
                                            'items_list'                 => __( 'Locations list', 'text_domain' ),
                                            'items_list_navigation'      => __( 'Locations list navigation', 'text_domain' ),
                                            'menu_name'                  => __( 'Locations', 'text_domain' ),
                                            'name'                       => _x( 'Locations', 'Taxonomy General Name', 'text_domain' ),
                                            'new_item_name'              => __( 'New Location Name', 'text_domain' ),
                                            'no_terms'                   => __( 'No items', 'text_domain' ),
                                            'not_found'                  => __( 'Not Found', 'text_domain' ),
                                            'parent_item'                => __( 'Parent Location', 'text_domain' ),
                                            'parent_item_colon'          => __( 'Parent Location:', 'text_domain' ),
                                            'popular_items'              => __( 'Popular Locations', 'text_domain' ),
                                            'search_items'               => __( 'Search Locations', 'text_domain' ),
                                            'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
                                            'singular_name'              => _x( 'LendingQ Locations', 'Taxonomy Singular Name', 'text_domain' ),
                                            'update_item'                => __( 'Update Location', 'text_domain' ),
                                            'view_item'                  => __( 'View Location', 'text_domain' ),
                                        ),
                                        'rewrite'                    => array( 'slug' => 'lendingq_location' ),
                                        'hierarchical'               => false,
                                        'public'                     => true,
                                        'show_ui'                    => true,
                                        'show_in_quick_edit'         => false,
                                        'meta_box_cb'                => 'post_categories_meta_box',
                                        'show_admin_column'          => true,
                                        'show_in_nav_menus'          => true,
                                        'show_tagcloud'              => true,
                                    )
                                 );

    Example image of shared post types both displaying taxonomies.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Colin M Tomele

    (@maniacalv)

    This doesn’t work for either taxonomy, but it does for the default All and Add that WordPress creates.

    remove_submenu_page( 'edit.php?post_type=lendingq_hold', 'edit-tags.php?taxonomy=lendingq_location&post_type=lendingq_hold' );

    BUt this works:

    remove_submenu_page( 'edit.php?post_type=lendingq_hold', 'post-new.php?post_type=lendingq_hold' );

    Moderator bcworkz

    (@bcworkz)

    Indeed it does work. You could instead pass 'show_in_menu' => false, when registering. I think you realize that doing this does not stop someone from manually typing an URL and getting to the edit screen anyway. Of course hiding the menu item would stymie nearly everyone but WP coders. Since you are not completely hiding all UI elements, it’s probably good enough.

    Thread Starter Colin M Tomele

    (@maniacalv)

    Thanks! I need them to show on at least one of the taxonomies, I’d just prefer one instead of both. It’s not the biggest issue but it’s bugging me.

    I have tested and was able to remove all other links except the two custom taxonomies, under both custom post types. That part works.

    When I try removing the custom taxonomies, nothing happens. Nothing I’ve done has worked: I’ve tried changing the order of things and moved things around, different priorities, and lots of different slugs and links in all varieties and flavors.

    If I make them hidden in menu, is there an action I call if I want to manually add them back in to one custom post type?

    Thread Starter Colin M Tomele

    (@maniacalv)

    Also, my goal isn’t to stop anyone from accessing them, I’m just trying to get them to display in only one place, but I need to make sure I’m sharing the two taxonomies across my two post types.

    I have a post type that is a lending, and another that is an item.

    I have 2 taxonomies: location and item type.

    I’d really only like the taxonomy edit-tags.php links to show up for one of the custom post types.

    If I hide them, can I add_submenu_page and just call the now hidden link instead of a callback function?

    Moderator bcworkz

    (@bcworkz)

    I see. ‘show_in_menu’ would not give you the fine control of which sub-menu to use or not use. I’m not sure about passing links instead of a callback to add_submenu_page(). I vaguely recall there being a way to do so, but the URL ended up being pretty ugly. For the fine control over visibility you are after, I think removing it after the fact like you originally proposed would be perfectly acceptable.

    Determining the correct parameters can be tricky, but dumping out the global $submenu would help a lot to that end.

    Thread Starter Colin M Tomele

    (@maniacalv)

    Thank you! Looking up more about that and I think that trying filtering out from the global $submenu might be my next move.

    Thread Starter Colin M Tomele

    (@maniacalv)

    That did it. Easy and works a charm. Thank you!

    global $submenu;
    unset( $submenu['edit.php?post_type=lendingq_hold'][15] );
    unset( $submenu['edit.php?post_type=lendingq_hold'][16] );
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Shared Taxonomy, hide admin links in one’ is closed to new replies.