2016-10-11 15 views
0

私はカスタム投稿タイプが「従業員」です。私は、デフォルトのポストタイトルではなくポストIDを使用するようにスラッグを書き直そうとしています。 「書き換え」のカスタムポストタイプ機能でこれを行う簡単な方法はありますか?カスタム投稿タイプを使用する投稿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); 
} 
関連する問題