How to handle this wordpress custom post type rewrite problem?


i have a custom post type called "carrier", this cpt has a custom taxonomy called "carrier-category".
the cpt has the following rewrite: 'rewrite' => ['slug' => 'carrier/%category%']
the taxonomy has this rewrite: 'rewrite' => ['slug' => 'carrier-category', 'with_front' => false]

to replace the %category% i rewrite it with this function:

public function rewriteLink($post_link, $id = 0) {
    $post = get_post($id);
    if ( is_object( $post ) && is_singular('carrier') ){
        $terms = wp_get_object_terms( $post->ID, 'carrier-categories' );
        if( $terms ){
            return str_replace( '%category%' , $terms[0]->slug , $post_link );
    return $post_link;

so that i get a permalink like "localhost/carrier/professionals/xyz" for a post in my cpt.

i need now to add a normal page with this structure: localhost/carrier/about-company
but if i add a page as child from the page "carrier" i wil get 404.
how to fix my rewrite, or is it a other problem?

Tobias 2 months 0 Answers 10 views 0

Leave an answer