カスタム投稿タイプ(スラッグ)のパーマーリンクの最後に拡張子をつける

カスタム投稿タイプのスラッグの後ろに拡張子をつける方法

今回は/customer/%customer%.html
例) /customer/voice.html スラッグ表示になる

function mytheme_init() {
    global $wp_rewrite;
    $wp_rewrite->use_trailing_slashes=false;//最後のスラッシュ無し
    $queryarg = 'post_type=customer&name=';//クエリ作成
    $wp_rewrite->add_rewrite_tag('%customer%', '([^/]+)', $queryarg);
    $customer_struct='/customer/%customer%.html';
    $wp_rewrite->add_permastruct('customer', $customer_struct);
}
add_action( 'init', 'mytheme_init' );

今回のポイント

$queryarg = ‘post_type=customer&name=’;//クエリ作成
の部分で、&name=にすることが重要!!
ネットで検索した場合、IDにする方法しかなく&p=の記述しか探せなかった

パーマリンクを変更後、404エラーになってしまう場合

管理画面より
設定 > パーマーリンク設定 > 設定を保存
をして再設定する