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

Add multiple custom post type issue

programmeradmin1浏览0评论

I want to make custom post types in my WordPress site. For that I used the register_post_type method in my functions.php, but why is only one custom post type showing in my admin page?

The code is shown below:

function create_my_custom_posts() {
    register_post_type( 'career_post', array(
        'labels' => array(
            'name' => __( 'Careers' ),
            'singular_name' => __( 'Career' ),
            'add_new' => __( 'Add New' ),
            'add_new_item' => __( 'Add New Career' ),
            'new_item' => __( 'New Career' ),
            'view_item' => __( 'View Career' ),
            'search_items' => __( 'Search Careers' ),
            'all_items' => __( 'All Careers' ),
            'add_new_item' => __( 'Add New Career' ),
            'not_found' => __( 'No Openings Yet' )
        ),
        'description' => 'job openings in uvionics tech',
        'public' => true,
        'has_archive' => true,
        'menu_position' => 5
    ) );
    register_post_type( 'employees_comnts_post', array(
        'labels' => array(
            'name' => __( 'Emps Comnts' ),
            'singular_name' => __( 'Emp Comnt' ),
            'add_new' => __( 'Add New' ),
            'add_new_item' => __( 'Add New Comnt' ),
            'new_item' => __( 'New Comnt' ),
            'view_item' => __( 'View Comnt' ),
            'search_items' => __( 'Search Comnts' ),
            'all_items' => __( 'All Comnts' ),
            'add_new_item' => __( 'Add New Comnt' ),
            'not_found' => __( 'No Comnts Yet' )
        ),
        'description' => 'Employees comments about life in company',
        'public' => true,
        'has_archive' => true,
        'menu_position' => 5
    ) );
    flush_rewrite_rules( false );
}
add_action( 'init', 'create_my_custom_posts' );

I want to make custom post types in my WordPress site. For that I used the register_post_type method in my functions.php, but why is only one custom post type showing in my admin page?

The code is shown below:

function create_my_custom_posts() {
    register_post_type( 'career_post', array(
        'labels' => array(
            'name' => __( 'Careers' ),
            'singular_name' => __( 'Career' ),
            'add_new' => __( 'Add New' ),
            'add_new_item' => __( 'Add New Career' ),
            'new_item' => __( 'New Career' ),
            'view_item' => __( 'View Career' ),
            'search_items' => __( 'Search Careers' ),
            'all_items' => __( 'All Careers' ),
            'add_new_item' => __( 'Add New Career' ),
            'not_found' => __( 'No Openings Yet' )
        ),
        'description' => 'job openings in uvionics tech',
        'public' => true,
        'has_archive' => true,
        'menu_position' => 5
    ) );
    register_post_type( 'employees_comnts_post', array(
        'labels' => array(
            'name' => __( 'Emps Comnts' ),
            'singular_name' => __( 'Emp Comnt' ),
            'add_new' => __( 'Add New' ),
            'add_new_item' => __( 'Add New Comnt' ),
            'new_item' => __( 'New Comnt' ),
            'view_item' => __( 'View Comnt' ),
            'search_items' => __( 'Search Comnts' ),
            'all_items' => __( 'All Comnts' ),
            'add_new_item' => __( 'Add New Comnt' ),
            'not_found' => __( 'No Comnts Yet' )
        ),
        'description' => 'Employees comments about life in company',
        'public' => true,
        'has_archive' => true,
        'menu_position' => 5
    ) );
    flush_rewrite_rules( false );
}
add_action( 'init', 'create_my_custom_posts' );
Share Improve this question edited Apr 8, 2016 at 6:03 Gabriel 2,24810 gold badges22 silver badges24 bronze badges asked Apr 7, 2016 at 9:34 suhail csuhail c 1131 silver badge4 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 2

In the documentation it is written that post type must be max. 20 characters, cannot contain capital letters or spaces.

In my case problem was that I was registering twice with same name with different parameters into it. Just had to make post_type different. Problem in both cases was

 register_post_type('custom', $arrgs); 
  register_post_type('custom', $arrgs);

Solution was to name post_type differently.

   register_post_type('custom', $arrgs);
   register_post_type('custom_2nd', $arrgs);

Try the following code for the addition of multiple custom post type

function codex_custom_init() {

      register_post_type(
        'testimonials', array(
          'labels' => array('name' => __( 'Careers' ), 'singular_name' => __( 'Career' ) ),
          'public' => true,
          'has_archive' => true,
          'supports' => array('title', 'editor', 'thumbnail')
        )
      );

      register_post_type(
        'home-messages', array(
          'labels' => array('name' => __( 'Emps Comnts' ), 'singular_name' => __( 'Emp Comnt' ) ),
          'public' => true,
          'has_archive' => true,
          'supports' => array('title', 'editor', 'thumbnail')
        )
      );

    }
    add_action( 'init', 'codex_custom_init' );

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论