📜  将自定义分类添加到永久链接 post_type_link - CSS 代码示例

📅  最后修改于: 2022-03-11 14:47:55.808000             🧑  作者: Mango

代码示例2
function wpa_course_post_link( $post_link, $id = 0 ){
    $post = get_post($id);  
    if ( is_object( $post ) ){
        $terms = wp_get_object_terms( $post->ID, 'course' );
        if( $terms ){
            return str_replace( '%course%' , $terms[0]->slug , $post_link );
        }
    }
    return $post_link;  
}
add_filter( 'post_type_link', 'wpa_course_post_link', 1, 3 );