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