Wordpress. Доступ к посту с N количеством подкаталогов
Как получить доступ к post_type если установить каталог www.site.com/faq/a/b/c/test-1 Создаю пост test-1, создаю термы a, b, c и создаю в папке темы файл single-faq.php но по ссылки www.site.com/faq/a/b/c/test-1 происходит редирект на 404.
add_action( 'init', 'register_faq_post_type' );
function register_faq_post_type() {
register_taxonomy( 'faqcat', [ 'faq' ], [
'label' => 'Раздел вопроса',
'public' => true,
'hierarchical' => true,
'rewrite' => array('slug'=>'faq', 'hierarchical'=>false, 'with_front'=>false, 'feed'=>false ),
'show_admin_column' => true,
] );
register_post_type( 'faq', [
'label' => 'Вопросы',
'public' => true,
'rewrite' => array( 'slug'=>'faq/%faqcat%', 'with_front'=>false, 'pages'=>false, 'feeds'=>false ),
'query_var' => true,
'supports' => array( 'title', 'editor' ),
] );
}
add_filter( 'post_type_link', 'faq_permalink', 1, 2 );
function faq_permalink( $permalink, $post ) {
if( strpos( $permalink, '%faqcat%' ) === false )
return $permalink;
$term_slug = '';
$terms = get_the_terms( $post, 'faqcat' );
if( ! is_wp_error( $terms ) && !empty( $terms ) && is_object( $terms[ 0 ] ) ) {
$term_slug .= $terms[ 2 ]->slug . '/' . $terms[ 1 ]->slug . '/' . $terms[ 0 ]->slug;
} else {
$term_slug = 'no-faqcat';
}
return str_replace( '%faqcat%', $term_slug, $permalink );
}