1

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' );
1

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

  • Still not working – suhail c Apr 7 '16 at 9:50
  • My bad, i tested it and i got it working if you change your post type from employees_comnts_post to employees_comnts. Ill find out the reason why – Marttin Notta Apr 7 '16 at 9:54
  • In the documentation it it written that post type cannot be longer than 20 chars and must not contain spaces and capital letters – Marttin Notta Apr 7 '16 at 9:55
0

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

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.