LoginSignup
1

More than 5 years have passed since last update.

【WordPress】カスタム投稿タイプを他の投稿タイプの入れ子にしてサブメニューとして表示させる方法

Posted at

カスタム投稿タイプを通常の投稿や固定ページの入れ子にする方法を書いていきます。

show_in_menuパラメータを利用する

メニューのどこに表示するかを設定する場合は、menu_positionパラメータを利用しますが、何かのサブメニューとして表示させる場合はshow_in_menuパラメータを使います。

functions.php
function create_custom_post_type() { 
    register_post_type('custom_post_type',
        array(
            'labels' => array(
            'name' => 'カスタム投稿タイプ',
            'singular_name' => 'カスタム投稿タイプ'
        ),
        'public' => true,
        'show_ui' => true,
        'has_archive' => true,
        'supports' => array('title','editor','author','thumbnail','excerpt','custom-fields','comments'),
        'show_in_menu' => 'edit.php' //通常の投稿タイプのサブメニューとする場合
        )
    );
}
add_action('init','create_custom_post_type');

上記コードは、通常の投稿タイプのサブメニューとする例です。他の投稿タイプのサブメニューにしたい場合は、edit.php?post_type={任意の投稿タイプ名}と指定すればいい形となります。
なので、固定ページのサブメニューにしたい場合は以下のように指定します。

'show_in_menu' => 'edit.php?post_type=page'

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1