admin管理员组文章数量:1129798
I'm attempting to add a category of each child post to that post's permalink. The post type is called lessons
. I have a taxonomy called Child Categories
that contains the terms workbooks
and workbook-solutions
I would like to make it so that if a post is a child of another post and contains either of the terms it is written as the following.
lessons/this-is-a-parent-post/workbooks/this-is-a-child-post
lessons/this-is-a-parent-post/workbook-solutions/this-is-a-child-post
This is the code I've written so far, but it hasn't resulted in the links rewriting.
add_action( 'init', 'add_taxonomy_to_child_post_url' );
function add_taxonomy_to_child_post_url() {
global $post;
if ( has_term( 'workbooks', $post ) && $post->post_parent ) {
add_rewrite_rule(
'^lessons/([^/]*)/([^/]*)/([^/]*)/?$',
'index.php?post_type=lessons&child-categories=$matches[1]&name=$matches[3]',
'top'
);
}
return $post_link;
}
本文标签: custom taxonomyAdding Category to Child Posts Permalink
版权声明:本文标题:custom taxonomy - Adding Category to Child Posts Permalink 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736699532a1948356.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论