multiple custom post type not being registered in wordpress

function custom_post_type(){

    //post type for popular sight seeing

    $labels = array(
        'name' => _x( 'popular_site_seeing', 'Post Type General Name', 'travel' ),
        'singular_name'=> _x( 'popular_site_seeing', 'Post Type Singular Name', 'travel' ),

        );

    $args = array(
        'label'               => __( 'popular_site_seeing', 'travel' ),
        'description'         => __( 'popular_site_seeing', 'travel' ),
        'labels'              => $labels,

        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),



        'taxonomies'          => array( 'genres' ),

        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'has_archive'         => true,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
        );

    // Registering popular_site_seeing
    register_post_type( 'popular_site_seeing', $args);



    //post type for popular_treking_climbing

    $labels= array(
        'name' => _x( 'popular_treking_climbing', 'Post Type General Name', 'travel' ),
        'singular_name'=> _x( 'popular_treking_climbing', 'Post Type Singular Name', 'travel' ),

        );

    $args = array(
        'label'               => __( 'popular_treking_climbing', 'travel' ),
        'description'         => __( 'popular_treking_climbing', 'travel' ),
        'labels'              => $labels,

        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),


        'taxonomies'          => array( 'genres' ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'has_archive'         => true,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
        );







    //registering popular_treking_climbing
    register_post_type( 'popular_treking_climbing', $args);




}



add_action( 'init', 'custom_post_type' );

as you can see i am trying to make two custom post types in wordpress,one is called popular_site_seeing and another is called,popular_treking_climbing.the custom post popular_site_seeing is being registered and i can access it from wp admin panel but,another post type popular_treking_climbing is not shown on wp admin panel.what am i doing wrong here? everywhere i searched,it says the way i am doing is the correct way.

Related posts

1 comment

  1. WordPress custom post type name length longer than 20 characters

    WordPress is standard using a max of 20 characters for the custom post type name. You can add the code for a new custom post type in your functions.php but if the name is longer than 20 characters WordPress doesn’t accept it.

    I’ve searched for it and found the solution to get a custom post type with a name longer than 20 characters:

    1. Open in /wp-includes the post.php file and search for the following line:

      if ( strlen( $post_type ) > 20 )
      return new WP_Error( ‘post_type_too_long’, __( ‘Post types cannot exceed 20 characters in length’ ) );

    2. Change this line to: (I took 50 characters in my example)

      if ( strlen( $post_type ) > 50 )
      return new WP_Error( ‘post_type_too_long’, __( ‘Post types cannot exceed 50 characters in length’ ) );

    3. Then open your database and edit the wp_posts > post_type column from 20 characters to 50 characters.

    Remember that if you update WordPress you need to do these steps every time.

    better way is you must give short name of your post type (less then 20 character).

Comments are closed.