我知道这篇文章可能很旧,但为了防止其他人正在搜索执行此操作的函数,我写了一篇$post\\u类型必须作为变量传递:)
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 );
}
}
希望有帮助!:)