我用以下代码注册自定义帖子类型:
register_post_type( 'gallerydoc', array(
'labels' => array(
'name' => __( 'Gallery Docs' ),
'singular_name' => __( 'Gallery Doc' )
),
'public' => true,
'publicly_queryable' => false,
// '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
// '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
'capability_type' => 'page',
'map_meta_cap' => true,
'menu_position' => 20,
'hierarchical' => true,
'rewrite' => false,
'query_var' => false,
'delete_with_user' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
'show_in_rest' => true,
'rest_base' => 'pages',
'rest_controller_class' => 'WP_REST_Posts_Controller',
) );
我从注册页面类型的functions.php
复制了代码。
我唯一注释掉的是写着“仅供内部使用,不要使用”的行。
但是自定义类型仍然不像页面或帖子类型那样。
自定义帖子类型:
我读到自定义帖子类型不能将其子句直接放在根目录下:
Wordpress - Page and custom post type with this same slug
因为这会与页面和帖子冲突。但是,页面和帖子之间的配合很好。
那为什么我的自定义帖子类型也不能做到这一点?
答案 0 :(得分:0)
请设置'publicly_queryable' => true,
和'rewrite' => true,
,以便您可以查看链接并进行编辑。
另请找到以下代码。
register_post_type( 'gallerydoc', array(
'labels' => array(
'name' => __( 'Gallery Docs' ),
'singular_name' => __( 'Gallery Doc' )
),
'public' => true,
'publicly_queryable' => true,
// '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
// '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
'capability_type' => 'page',
'map_meta_cap' => true,
'menu_position' => 20,
'hierarchical' => true,
'rewrite' => true,
'query_var' => false,
'delete_with_user' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
'show_in_rest' => true,
'rest_base' => 'pages',
'rest_controller_class' => 'WP_REST_Posts_Controller',
) );