2016-06-28 17 views
1

當將'hierarchical'=> true設置爲自定義帖子類型並將父項分配給具有此自定義帖子類型的頁面時,將引發404。可以使這項工作成爲可能嗎?WordPress的:我如何添加到一個自定義職位類型的子頁面其父母爲slu??

預期的結果:http://example.com/parent-page/page-title/

這工作與WordPress正常的網頁,但與自定義文章類型(404未找到)。

在此先感謝!

+0

這個永久鏈接結構是否可以運行:'example.com/post-type/parent-slug/child-slug'?或者你是否不希望永久鏈接中的帖子類型? – JoeMoe1984

+0

我不希望帖子類型在永久鏈接:( – Maxi

+0

我剛剛更新了我的答案,現在它清楚:) – JoeMoe1984

回答

1

由於我剛剛注意到您需要的頁面結構完全像頁面,您可以在註冊帖子類型時修改rewrite參數。這裏是如何使它就像網頁結構的例子:

$args = array(
    'labels'    => $labels, 
    'hierarchical'  => true, // just to get parent child relationships with your custom post [but you already knew this part] 
    'description'   => 'Your custom post type description here', 
    'has_archive'   => false, 
    'rewrite'    => array('slug' => '/'), // we rewrite the slug to the root url so that it has no post type prefix 
    'with_front'   => false, // This is optional but just in case your posts are set to /blog/post-name this will make it /post-name for your custom post type 
    'capability_type'  => 'post', 
    'supports'   => array(
     'title', 'editor', 'author', 'thumbnail', 'page-attributes' 
     ) 
); 

register_post_type('post_type', $args); 

另外,還要確保你更新的永久鏈接結構進行這些修改完成後,WordPress的可以重寫規則。

相關問題