2016-10-11 3 views
0

저는 맞춤 게시 유형이 '종업원'입니다. 나는 기본 게시물 제목보다는 게시물 ID를 사용하도록 슬러그를 다시 작성하려고합니다. '다시 쓰기'아래의 맞춤 게시 유형 기능에서이 작업을 수행 할 수있는 간단한 방법이 있습니까? 이 같은게시물 유형 대신 게시물 제목이 아닌 퍼머 링크에 ID를 사용하십시오.

뭔가 :

'rewrite' => [ 
     'with_front' => false, 
     'slug' => 'employee/' . %post_id%, 
    ] 

답변

1

이 다음은 이전 프로젝트에 나를 위해 유사한 일이 -이 (테스트되지 않은) 문제 해결에 도움이 되었습니까?

'rewrite' => array(
    'with_front' => false, 
    'slug' => 'news/events/%employee_id%' 
) 


add_filter('post_type_link', 'custom_employee_permalink', 1, 3); 
function custom_employee_permalink($post_link, $id = 0, $leavename) { 
    if (strpos('%employee_id%', $post_link) === 'FALSE') { 
     return $post_link; 
    } 
    $post = &get_post($id); 
    if (is_wp_error($post) || $post->post_type != 'employee') { 
     return $post_link; 
    } 
    return str_replace('%employee_id%', $post->ID, $post_link); 
}