$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to display Custom Taxonomy under Custom Admin Menu?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to display Custom Taxonomy under Custom Admin Menu?

matteradmin10PV0评论

I have problem to display custom taxonomy under custom admin menu. Custom post types are displayed properly, but the taxonomy doesn't appear.

I added to custom post types: 'show_in_menu' => 'my-menu'

My Custom Menu

  • Custom Post Type 1
  • Custom Post Type 2
  • Custom Post Type 3
  • Custom Taxonomy that can be used by Post Type 1/2/3

What i need to do to display custom taxonomy?

UPDATE

Here's my code:

function create_custom_admin_menu() {
  add_menu_page(
    'My Menu',
    'My Menu',
    'read',
    'my-menu',
    '',
    'dashicons-admin-page',
    10
  );
}
add_action( 'admin_menu', 'create_custom_admin_menu' );


function create_custom_post_type_1() {
  $labels = array(
    'name' => _x( 'Custom Post 1' ),
    'singular_name' => _x( 'Custom Post 1' ),
    'menu_name' => __( 'Custom Post 1' ),
  );
  register_post_type( 'custom-post-type-1', array(
    'labels' => $labels,
    'has_archive' => false,
    'public' => true,
    'show_in_menu' => 'my-menu',
    'supports' => array( 'title', 'editor', 'auther', 'excerpt', 'custom-fields', 'thumbnail','comments' ),
    'taxonomies' => array( 'custom-taxonomy' ),
    'exclude_from_search' => false,
    'capability_type' => 'post',
    )
  );
}
add_action( 'init', 'create_custom_post_type_1' );


function register_custom_taxonomy() {
  $labels = array(
    'name' => _x( 'Custom Taxonomy'),
    'singular_name' => _x( 'Custom Taxonomy' ),
    'menu_name' => __( 'Custom Taxonomy' ),
  );
  register_taxonomy( 'custom-taxonomy', 'my-menu', array(
    'hierarchical' => true,
    'labels' => $labels,
    'query_var' => true,
    'show_admin_column' => true
  ) );
}
add_action( 'init', 'register_custom_taxonomy' );

UPDATE 2

I tried it all and nothing works:

register_taxonomy( 'custom-taxonomy', 'my-menu', [...]


register_taxonomy( 'custom-taxonomy', 'custom-post-type-1', [...]


register_taxonomy( 'custom-taxonomy', array('custom-post-type-1', 'custom-post-type-2', 'custom-post-type-3' ), [...]

I have problem to display custom taxonomy under custom admin menu. Custom post types are displayed properly, but the taxonomy doesn't appear.

I added to custom post types: 'show_in_menu' => 'my-menu'

My Custom Menu

  • Custom Post Type 1
  • Custom Post Type 2
  • Custom Post Type 3
  • Custom Taxonomy that can be used by Post Type 1/2/3

What i need to do to display custom taxonomy?

UPDATE

Here's my code:

function create_custom_admin_menu() {
  add_menu_page(
    'My Menu',
    'My Menu',
    'read',
    'my-menu',
    '',
    'dashicons-admin-page',
    10
  );
}
add_action( 'admin_menu', 'create_custom_admin_menu' );


function create_custom_post_type_1() {
  $labels = array(
    'name' => _x( 'Custom Post 1' ),
    'singular_name' => _x( 'Custom Post 1' ),
    'menu_name' => __( 'Custom Post 1' ),
  );
  register_post_type( 'custom-post-type-1', array(
    'labels' => $labels,
    'has_archive' => false,
    'public' => true,
    'show_in_menu' => 'my-menu',
    'supports' => array( 'title', 'editor', 'auther', 'excerpt', 'custom-fields', 'thumbnail','comments' ),
    'taxonomies' => array( 'custom-taxonomy' ),
    'exclude_from_search' => false,
    'capability_type' => 'post',
    )
  );
}
add_action( 'init', 'create_custom_post_type_1' );


function register_custom_taxonomy() {
  $labels = array(
    'name' => _x( 'Custom Taxonomy'),
    'singular_name' => _x( 'Custom Taxonomy' ),
    'menu_name' => __( 'Custom Taxonomy' ),
  );
  register_taxonomy( 'custom-taxonomy', 'my-menu', array(
    'hierarchical' => true,
    'labels' => $labels,
    'query_var' => true,
    'show_admin_column' => true
  ) );
}
add_action( 'init', 'register_custom_taxonomy' );

UPDATE 2

I tried it all and nothing works:

register_taxonomy( 'custom-taxonomy', 'my-menu', [...]


register_taxonomy( 'custom-taxonomy', 'custom-post-type-1', [...]


register_taxonomy( 'custom-taxonomy', array('custom-post-type-1', 'custom-post-type-2', 'custom-post-type-3' ), [...]
Share Improve this question edited Feb 9, 2019 at 13:23 Avigo asked Feb 9, 2019 at 12:31 AvigoAvigo 377 bronze badges 2
  • can you show your full attempt in code? – klewis Commented Feb 9, 2019 at 12:51
  • @klewis I've updated the question – Avigo Commented Feb 9, 2019 at 13:08
Add a comment  | 

2 Answers 2

Reset to default 2

You haven't properly registered the taxonomy for your post type. You register your post type like this:

register_post_type( 'custom-post-type-1',

Meaning that your post type is named custom-post-type-1. But when you register the taxonomy, you're registering it for a post type called my-menu"

register_taxonomy( 'custom-taxonomy', 'my-menu',

You need to register your taxonomy for your post type:

register_taxonomy( 'custom-taxonomy', 'custom-post-type-1',

I think that there is an issue with your plugins. That's why, custom taxonomy is not showing up.

Turn off all the plugins. Then enable them one at a time. In this way, you can find the defective one. You have to remove it and use an alternate option.

Post a comment

comment list (0)

  1. No comments so far