admin管理员组文章数量:1196548
I'm trying to customize the permalink of some child pages.
I have this structure:
example/story/story-name-slug/chapter-slug/page-slug
And I'm trying to transforming that structure into this:
example/section/page-slug
But also I want to keep the other links active, so in the end I should have the following:
example/story
-> archive of all story;
example/story/story-name-slug
-> list of all chapters;
example/section/page-slug
-> page with customized url.
Keep in mind that example/story/story-name-slug/chapter-slug
is not a page that can be visited by users. It's only used to archive the hierarchical relation between pages.
At the moment I got the url structure working with the following code in functions.php:
add_filter('page_link', 'custom_permalink', 10, 3);
add_filter('page_type_link', 'custom_permalink', 10, 3);
function custom_permalink($permalink, $post_id) {
$post = get_post($post_id);
$post_name = $post->post_name;
$id_chapter = $post->post_parent;
$id_story = wp_get_post_parent_id($id_chapter);
$id_stories = wp_get_post_parent_id($id_story);
if ($id_chapter !== 0 && $id_story !== 0 && $id_stories ) {
// the static base url is just for testing
$permalink = 'example/section/' . $post_name ;
} else {
$permalink = $permalink;
}
return $permalink;
}
This works but not as it shoudl, I get the right URLs on the right pages but when I visit those pages I get a 404 Error not found.
After some digging in the sql queris that get executed I think that the problem is that WP is selecting wp_posts.post_type = 'attachment'
instead of wp_posts.post_type = 'page'
.
I think that a rewrite rule is needed somewhere to specify in the sql query what to select, but this goes over my current capabilities.
If it's needed I can provide all the queries that get executed on the page with and without the filter that I added.
Thanks!
本文标签: filtersCustom child page permalink
版权声明:本文标题:filters - Custom child page permalink 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738501658a2090304.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论