JavaScript
2
Вклад в тег
register_taxonomy(
'type_work',
'portfolio',
array(
'rewrite' => array( 'slug' => 'portfolio', 'with_front' => false )
)
);
register_post_type(
'portfolio',
array(
'rewrite' => array( 'slug' => 'portfolio/%type_work%', 'with_front' => false ),
'has_archive' => 'portfolio'
)
);
function wpa_portfolio_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'portfolio' ){
$terms = wp_get_object_terms( $post->ID, 'type_work' );
if( $terms ){
return str_replace( '%type_work%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'wpa_portfolio_permalinks', 1, 2 );
add_action('init', 'do_rewrite');
function do_rewrite(){
add_rewrite_rule( 'test', 'index.php?p=17', 'top' );
flush_rewrite_rules();
}