admin管理员组文章数量:1129197
I can get the permalink of a specific post tag or category, but what if I want to get the permalink of a custom post type? I can't find anything in the Codex or anywhere else about how to do this.
I can get the permalink of a specific post tag or category, but what if I want to get the permalink of a custom post type? I can't find anything in the Codex or anywhere else about how to do this.
Share Improve this question asked Oct 25, 2011 at 2:26 Industrial ThemesIndustrial Themes 7551 gold badge9 silver badges22 bronze badges5 Answers
Reset to default 32How about href="<?php echo get_post_type_archive_link( $post_type ); ?>"
, where $post_type
is your post type?
Further reading: Codex
Within the loop, you can simply use the_permalink()
. Outside of the loop, you can use get_permalink( $id )
.
Or, for what it's worth, get_term_link($term, $taxonomy);
- Codex.
I know this post might be old but just in case someone else is searching the function that does this, here's the one i wrote. $post_type must be passed as a variable :)
if( !function_exists( 'wp_get_post_type_link' ) ){
function wp_get_post_type_link( &$post_type ){
global $wp_rewrite;
if ( ! $post_type_obj = get_post_type_object( $post_type ) )
return false;
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {
$struct = $post_type_obj->rewrite['slug'] ;
if ( $post_type_obj->rewrite['with_front'] )
$struct = $wp_rewrite->front . $struct;
else
$struct = $wp_rewrite->root . $struct;
$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
} else {
$link = home_url( '?post_type=' . $post_type );
}
return apply_filters( 'the_permalink', $link );
}
}
Hope it helps ! :)
@Stefan KRUGER
curious why the value is passed by reference: &$post_type
aside: I dont' understand why i can supply an answer, which is not what this is, but NOT a comment, which is what this is. that seems backward.
本文标签: How do I get the permalink of a custom post type
版权声明:本文标题:How do I get the permalink of a custom post type? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736697205a1948242.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论