The goal is to have a structure like this: example.com/tax_1/tax_2/post_name
This code produces the right structure but the post can't be found (404)
// Register custom post types
function register_work() {
$args = array(
'public' => true,
'label' => 'Projekt',
'menu_name' => 'work',
'menu_icon' => 'dashicons-welcome-view-site',
'has_archive' => false,
'supports' => array( 'thumbnail', 'title' ),
'rewrite' => array(
'slug' => '%filter_1%/%filter_2%',
'with_front' => false
)
);
register_post_type( 'work', $args );
}
add_action( 'init', 'register_work' );
// Register tax
function work_tax() {
register_taxonomy(
'filter',
'work',
array(
'label' => __( 'Tags' ),
'hierarchical' => true,
'rewrite' => array(
'slug' => 'filter',
'with_front' => false
)
)
);
}
add_action( 'init', 'work_tax' );
// Replace permalink slug
function custom_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'work' ){
$terms = wp_get_object_terms( $post->ID, 'filter' );
if( $terms ){
$find = array('%filter_1%','%filter_2%');
$replace = array($terms[0]->slug,$terms[1]->slug);
return str_replace($find, $replace, $post_link);
}
}
return $post_link;
}
add_filter( 'post_type_link', 'custom_permalinks', 1, 2 );
I have regenerated the .htaccess file by saving the permalinks in the settings menu.
Does anyone know if it even possible to do this?