admin管理员组文章数量:1416332
I have changed my post type URL structure to have the taxonomy type
in the URL as well by doing this:
In register_post_type
(Post type: release
):
'rewrite' => array('slug' => __('releases/%type%', 'mytheme'), 'with_front' => false),
In functions.php
function wpa_show_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'release' ){
$terms = wp_get_object_terms( $post->ID, 'type' );
if( $terms ){
return str_replace( '%type%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );
When I loop through the available types in my I need to generate the correct permalink for example /releases/movies/
but when I loop through get_terms
and display the link like this:
get_term_link($releaseType)
it returns /types/movies
. What would be the most elegant way to release the URL with the post type. I wanna avoid writing the urls hardcoded in case it changes.
本文标签: theme developmentGet taxonomy link with post type slug prefix
版权声明:本文标题:theme development - Get taxonomy link with post type slug prefix 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745249101a2649712.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论