skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search