admin管理员组文章数量:1425892
For a project I have a custom post type called Place. This custom post type can have a page as a parent, and that page can have other parent and so on. Place is always at the end of the sequence. At first I created this CPT as non hierarchical, but now I have been asked to reflect the page structure in the URLs (I created a custom metabox to select a page id in the post_parent field).
So I changed my CPT definition to enable the hierarchical setting and the URLs look as expected: /
Where "place-grandparent" and "place-parent" are page slugs. But my problem is that I follow that URL and it gives me error 404. I'm not sure if it is because the parent is of a different type or something else. But that would be weird considering that the URL looks good.
Here is my CPT definition:
function create_posttype() {
register_post_type(
'place',
array(
'labels' => array(
'name' => __( 'Places' ),
'singular_name' => __( 'Place' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array(
'slug' => 'place'
),
'hierarchical' => true,
'supports' => array(
'title',
'editor',
// 'page-attributes',
'custom-fields'
),
'menu_icon' => 'dashicons-location-alt',
'query_var' => true
)
);
}
add_action( 'init', 'create_posttype' );
What can I do to make this structure work? The place needs to have a page as parent, because the pages have widgets that show all the children Places.
Also, can I remove the "place" part at the beggining of the URL and still make it work?
I'm a newbie with Wordpress so any help would be much appreciated.
本文标签: permalinksEnabling hierarchical in a Custom Post Type gives error 404
版权声明:本文标题:permalinks - Enabling hierarchical in a Custom Post Type gives error 404 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745458621a2659220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论