WordPress custom post type - Invalid post type? -
why invalid post type for:
function keyword_pages_init() { $args = array( 'label' => 'keywords', 'public' => true, 'show_ui' => true, 'capability_type' => 'page', 'hierarchical' => false, 'rewrite' => array('slug' => 'keyword'), 'query_var' => true, 'menu_icon' => 'dashicons-admin-page', 'supports' => array( 'title', 'editor', 'excerpt', // 'trackbacks', //'custom-fields', //'comments', 'revisions', 'thumbnail', 'author', 'page-attributes', ) ); register_post_type( 'keyword', $args ); } add_action( 'init', 'keyword_pages_init' ); what gone wrong?
but fine keyword s:
function keyword_pages_init() { $args = array( 'label' => 'keywords', 'public' => true, 'show_ui' => true, 'capability_type' => 'page', 'hierarchical' => false, 'rewrite' => array('slug' => 'keywords'), 'query_var' => true, 'menu_icon' => 'dashicons-admin-page', 'supports' => array( 'title', 'editor', 'excerpt', // 'trackbacks', //'custom-fields', //'comments', 'revisions', 'thumbnail', 'author', 'page-attributes', ) ); register_post_type( 'keywords', $args ); } add_action( 'init', 'keyword_pages_init' ); why!??
but works new function name!
function keyword2_pages_init() { $args = array( 'label' => 'keywordsx', 'public' => true, 'show_ui' => true, 'capability_type' => 'page', 'hierarchical' => false, 'rewrite' => array('slug' => 'keyword'), 'query_var' => true, 'menu_icon' => 'dashicons-admin-page', 'supports' => array( 'title', 'editor', 'excerpt', // 'trackbacks', //'custom-fields', //'comments', 'revisions', 'thumbnail', 'author', 'page-attributes', ) ); register_post_type( 'keyword', $args ); } add_action( 'init', 'keyword2_pages_init' ); why!!?
the custom post type "keyword" registered. list registered post types function:
var_dump(get_post_types());
https://codex.wordpress.org/function_reference/get_post_types
basically name "keyword" legal - docs:
$post_type (string) (required) post type. (max. 20 characters, cannot contain capital letters or spaces) default: none
https://codex.wordpress.org/function_reference/register_post_type
if sure slug keyword not used else , error still exists may bug in wordpress core. if can find report it.
especially in past hundreds of wordpress projects have come across issue 1 ore 2 times.
if post type exists - answer how de-register post type can found here (however possibly registered reason plugin or similar): https://wordpress.stackexchange.com/questions/3820/deregister-custom-post-types
furthermore should note add_action has $priority argument. priority may matter.
https://developer.wordpress.org/reference/functions/add_action/
Comments
Post a Comment