Home > OS >  cannot register post type in wordpress
cannot register post type in wordpress

Time:12-31

I am having an issue while register new post type in wordpress. Post slug web-to-print-glossary or web-to-print-glossaries not working, but webtoprint-glossary is working. can someone please explain what is going on?

This is my code

$labels = [
    "name" => esc_html__( "Web to Print Glossary" ),
    "singular_name" => esc_html__( "Web to Print Glossary" ),
];

$args = [
    "label" => esc_html__( "Web to Print Glossary" ),
    "labels" => $labels,
    "description" => "",
    "public" => true,
    "publicly_queryable" => true,
    "show_ui" => true,
    "show_in_rest" => true,
    "rest_base" => "web-to-print-glossaries",
    "rest_controller_class" => "WP_REST_Posts_Controller",
    "rest_namespace" => "wp/v2",
    "has_archive" => false,
    "show_in_menu" => true,
    "show_in_nav_menus" => true,
    "delete_with_user" => false,
    "exclude_from_search" => false,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => false,
    "can_export" => false,
    "rewrite" => [ "slug" => "web-to-print-glossaries", "with_front" => true ],
    "query_var" => true,
    "supports" => [ "title", "editor", "thumbnail" ],
    "show_in_graphql" => false,
];

register_post_type( "web-to-print-glossaries", $args );

and

CodePudding user response:

It is because of post type key exceeded the characters limit. 20 is the maximum allowed character limit to register post type.

You can find the reference here

CodePudding user response:

WP database reserved for post_type varchar(20) You need trancate your name ("web-to-print-glossaries") to 20 chars. Now it has 23 chars. enter image description here

  • Related