最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I order multiple custom post types in the same menu position ( menu_position = 20 - below Pages)?

programmeradmin0浏览0评论

These are the args I used to get "Artists" display above "Master Artist Lookup" using the "menu_position" parameter. However , still does not display in menu correctly

        $args = [
            'label'              => __('Artists', SMF_CORE_NAME),
            'labels'             => [
                'name'          => __('Artists', SMF_CORE_NAME),
                'singular_name' => __('Artist'),
                'add_new_item'  => __('Add New Artist', SMF_CORE_NAME),
                'add_new'       => __('Add New Artist', SMF_CORE_NAME),
                'new_item'      => __('Add New Artist', SMF_CORE_NAME),
                'all_items'     => __('All Artists', SMF_CORE_NAME),
                'edit_item'     => __('Edit Artist', SMF_CORE_NAME)
            ],
            'supports'           => ['title', 'thumbnail'],
            'hierarchical'       => false,
            'public'             => true,
            'menu_icon'          => 'dashicons-format-audio',
            'can_export'         => true,
            'has_archive'        => false,
            'publicly_queryable' => false,
            'menu_position' => '20.1',
        ];


$args = [
    'label'              => __('Master Artist Lookup', SMF_CORE_NAME),
    'labels'             => [
        'name'          => __('Master Artist Lookup', SMF_CORE_NAME),
        'singular_name' => __('Master Artist Lookup'),
        'add_new_item'  => __('Add New Artist', SMF_CORE_NAME),
        'add_new'       => __('Add New Artist', SMF_CORE_NAME),
        'new_item'      => __('Add New Artist', SMF_CORE_NAME),
        'all_items'     => __('All Artists', SMF_CORE_NAME),
        'edit_item'     => __('Edit Artist', SMF_CORE_NAME)
    ],
    'supports'           => ['title', 'thumbnail'],
    'hierarchical'       => false,
    'public'             => true,
    'menu_icon'          => 'dashicons-format-audio',
    'can_export'         => true,
    'has_archive'        => false,
    'publicly_queryable' => false,
    'menu_position' => '20.2',
        ];

These are the args I used to get "Artists" display above "Master Artist Lookup" using the "menu_position" parameter. However , still does not display in menu correctly

        $args = [
            'label'              => __('Artists', SMF_CORE_NAME),
            'labels'             => [
                'name'          => __('Artists', SMF_CORE_NAME),
                'singular_name' => __('Artist'),
                'add_new_item'  => __('Add New Artist', SMF_CORE_NAME),
                'add_new'       => __('Add New Artist', SMF_CORE_NAME),
                'new_item'      => __('Add New Artist', SMF_CORE_NAME),
                'all_items'     => __('All Artists', SMF_CORE_NAME),
                'edit_item'     => __('Edit Artist', SMF_CORE_NAME)
            ],
            'supports'           => ['title', 'thumbnail'],
            'hierarchical'       => false,
            'public'             => true,
            'menu_icon'          => 'dashicons-format-audio',
            'can_export'         => true,
            'has_archive'        => false,
            'publicly_queryable' => false,
            'menu_position' => '20.1',
        ];


$args = [
    'label'              => __('Master Artist Lookup', SMF_CORE_NAME),
    'labels'             => [
        'name'          => __('Master Artist Lookup', SMF_CORE_NAME),
        'singular_name' => __('Master Artist Lookup'),
        'add_new_item'  => __('Add New Artist', SMF_CORE_NAME),
        'add_new'       => __('Add New Artist', SMF_CORE_NAME),
        'new_item'      => __('Add New Artist', SMF_CORE_NAME),
        'all_items'     => __('All Artists', SMF_CORE_NAME),
        'edit_item'     => __('Edit Artist', SMF_CORE_NAME)
    ],
    'supports'           => ['title', 'thumbnail'],
    'hierarchical'       => false,
    'public'             => true,
    'menu_icon'          => 'dashicons-format-audio',
    'can_export'         => true,
    'has_archive'        => false,
    'publicly_queryable' => false,
    'menu_position' => '20.2',
        ];
Share Improve this question asked May 20, 2020 at 16:38 daily-learnerdaily-learner 1133 bronze badges 1
  • This has frustrated me for ages and all the documentation I've read in the codex and on other similar questions produces mixed results. It's super frustrating. I've used the decimal method but in quite a few instances have just left things as 'this is the best I'm going to get'. Would love to see some answers to this one. – Tony Djukic Commented May 20, 2020 at 17:24
Add a comment  | 

1 Answer 1

Reset to default 1

There are two ways to affect where CPTs appear in the admin menu: using menu_position and controlling when the CPTs are registered.

Using decimal numbers hasn't been reliable in my experience; using an integer like 21, 22, etc. has been more effective. If you have so many CPTs there aren't enough integers, the other trick is to register the one you want first first, then register the second, then register the third. By controlling the code order, and keeping the menu_position the same for all of them, WP will put them in the order you register them in.

发布评论

评论列表(0)

  1. 暂无评论