A
A
Alex-Broudy2020-07-07 00:23:53
WordPress
Alex-Broudy, 2020-07-07 00:23:53

Why doesn't it find child pages when using the custom url post type slug removal solution?

There is a parent (static) page "Services" and child pages: "Foundation" and "Roof".
The link to the "Foundation" page looks like this: mysite.ru/uslugi/fundament/

An arbitrary record type projects has been created for house projects.
To remove the projects slug from the home project url, I use the solution found on wp-kama:

function projects_post_type_rewrite() {
    global $wp_rewrite;
    $wp_rewrite->add_rewrite_tag("%projects%", '([^/]+)', "projects=");
    $wp_rewrite->add_permastruct('projects', '%projects%' );
}
add_action( 'init', 'projects_post_type_rewrite');
 
function projects_rewrite_conflicts( $request ) {
    if(!is_admin())
        $request['post_type'] = array('projects', 'post', 'page'); 
    return $request;
}
add_filter( 'request',  'projects_rewrite_conflicts' );


After adding this code to functions.php, I update the permalinks in the settings and when I try to open the "Foundation" page mysite.ru/uslugi/fundament/ it redirects to the parent page "Services" mysite.ru/uslugi/

Similarly with other parent pages.

What could be the problem? and how to fix it?
I will be glad for any help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question