Viewing 2 reply threads
  • Author
    Posts
    • #6135
      jasc
      Member

      Hi there,

      “Getting started with ..” is taking me no where. How do you put a custom post type under an admin menu.

      Say if I have top level menu done via code such as

      add_action('admin_menu', 'jcnow_plugin_menu');
      function jcnow_plugin_menu()
      {
          add_menu_page("Demo Plugin", "Demo Plugin", 'manage_options', "jc-demo-plugin", 'jcdemo_main', '', 10);
      }
      function jcdemo_main()
      {
          if (!current_user_can('manage_options')) {
              wp_die(__('You do not have sufficient permissions to access this page.'));
          }
          echo '<div class="wrap">';
          echo '<p>Hello</p>';
          echo '</div>';
      }
      
      

      I’ve added these lines of code below above code

      add_filter('piklist_post_types', 'piklist_jc_demo_categories');
      function piklist_jc_demo_categories($post_types)
      {
          $post_types['piklist_jccategories'] = array(
              'labels' => piklist('post_type_labels', 'Manage Categories')
          ,'title' => __('Enter a new Demo Title1')
          ,'menu_icon' => piklist_admin::responsive_admin() == true ? plugins_url('piklist/parts/img/piklist-menu-icon.svg') : plugins_url('piklist/parts/img/piklist-icon.png')
          ,'page_icon' => plugins_url('piklist/parts/img/piklist-page-icon-32.png')
          ,'supports' => array(
                  'title'
              ,'revisions'
              )
              ,'sub_menu'=>"admin.php?page=jc-demo-plugin"
          ,'public' => true
          ,'admin_body_class' => array (
                  'piklist-demonstration'
              ,'piklist-sample'
              )
          ,'has_archive' => true
          ,'rewrite' => array(
                  'slug' => 'piklist-categories'
              )
          ,'capability_type' => 'post'
          ,'edit_columns' => array(
                  'title' => __('Demo')
              ,'author' => __('Assigned to')
              )
          ,'hide_meta_box' => array(
                  'slug'
              ,'author'
              )
          ,'status' => array(
                  'draft' => array(
                      'label' => 'New'
                  ,'public' => true
                  )
              ,'demo' => array(
                      'label' => 'Demo'
                  ,'public' => true
                  ,'exclude_from_search' => true
                  ,'show_in_admin_all_list' => true
                  ,'show_in_admin_status_list' => true
                  )
              ,'lock' => array(
                      'label' => 'Lock'
                  ,'public' => true
                  )
              )
          );
      
          return $post_types;
      }

      This menu “Manage categories” is appearing under “Comments” menu item and not under “Demo Plugin”, what am I doing wrong. Plus how do I add custom fields just for this post type?

      Documentation is quite confusing, perhaps I haven’t get used to this idea yet.

      Any help will be much appreciated.

      Regards

      Jas

    • #6136
      jasc
      Member

      show_in_menu option seems to work, but not sure if its correct way to do it

      Jas

    • #6154
      Steve
      Keymaster

      Piklist works with register_post_type, and according to the WordPress codex show_in_menu is correct.

Viewing 2 reply threads
  • The topic ‘Putting a custom post type under an admin menu’ is closed to new replies.