[ad_1]
The simplest solution is to name one “docs” and the other “documentation”, or anything similarly different.
The more complex solution is to add a query to pre_get_posts to resolve the sub-pages if they exist.
This snippet, if installed as a plugin for example to wp-content/plugins/documentation-pages/documentation-pages.php, or to your theme’s functions.php, or to a Code Snippet plugin, should do it:
<?php
/**
* Plugin Name: Documentation Pages Query
* Description: Allow "documentation" sub-pages to resolve when "documentation" post type also exists.
* Plugin Author: 𝜑δ•ℂᴹ
* Author URI:
* Plugin URI:
* Version: 1
*/
add_action(
'pre_get_posts',
function( $query ){
if ( $query->is_main_query() && ! is_admin() ) {
$documentation_page_id = get_posts([
'post_type' => 'page',
'posts_per_page' => 1,
'post_status' => 'published',
'fields' => 'ids',
'name' => $query->get('documentation'),
'post_parent__in' => get_posts([
'post_type' => 'page',
'posts_per_page' => 1,
'post_status' => 'published',
'fields' => 'ids',
'name' => 'documentation'
]),
]);
if ( ! empty( $documentation_page_id ) ) {
$query->set( 'post_type', 'page' );
}
}
}
);
