One of two Custom Post types not being registered

An important notice from the Codex:

Do pay close attention to not having your custom post type identifier
exceed 20 characters though, as the post_type column in the database
is currently a VARCHAR field of that length.

Please check out:

echo strlen( 'informationtechnology' );

If you have WP_DEBUG activated, then you will see this warning:

register_post_type was called incorrectly. Post type names must be
between 1 and 20 characters in length. Please see Debugging in
WordPress for more information. (This message was added in version
4.2.)

so this is a good reminder to use it when developing your site 😉

This part of register_post_type() is responsible for this check, I missed it when I first skimmed through the function but confirmed it when I ran the example by @JoeyNg’ethe:

if ( empty( $post_type ) || strlen( $post_type ) > 20 ) {
    _doing_it_wrong(
        __FUNCTION__, 
        __( 'Post type names must be between 1 and 20 characters in length.' ), 
       '4.2' 
    );
    return new WP_Error( 
        'post_type_length_invalid',
        __( 'Post type names must be between 1 and 20 characters in length.' ) 
    );
}

EDIT

Look at the $post_type parameter when registering your post type

$post_type

(string) (required) Post type. (max. 20 characters, cannot contain
capital letters or spaces
)

Default: None

Leave a Comment