Closed kurudrive closed 6 months ago
@AtsushiA
設定 > パーマリンク設定で /news/%postname%/ にすると他のカスタム投稿タイプのURLにも news がついてしまう → 理解
で、ここから rewrite が true だと、具体的にどういう状態にしたい時に、どう 設定したものが、どうなってしまうかがちょっと理解出来ておらずどう修正してそれが意図した挙動なのか判断できないので改めて手順など記載いただけると助かります (´;ω;`)
@kurudrive お手数をおかけしてすみません。 パーマリンクの書き換え (任意) 設定を "パーマリンクを書き換えない"にすると Custom Post Type Permalinksでパーマリングの変更から該当のポストタイプのパーマリンクが変更できなくなってしまうのです
@AtsushiA 確認ありがとうございます。
まず、従来の設定の場合、event のカスタム投稿タイプの場合、Custom Post Type Permalinks で変更しようとすると http://localhost:8888/event/ 以下を変更可能
また、マスターのパーマリンクを /news/%postname%/ に変更すると http://localhost:8888/news/event/ 以下を変更可能
という状態になります。
これをどう形式に変更できれば要件クリアでしょうか?
news も event も含めずに自由に変更できるという事ですか(・w・?
@kurudrive こんな感じだけの設定を変更したいです。以前はこのような感じで対応してました。
//CustomPostType "news"のフロントでのリライトを無効に変更
function custom_new_permalink( $args, $post_type ) {
if ( 'news' !== $post_type ) {
return $args;
}
$news_args = array(
'rewrite' => array(
'slug' => 'news',
'with_front' => false,
'rewrite_slug' => false,
)
);
return array_merge( $args, $news_args );
}
add_filter( 'register_post_type_args', 'custom_new_permalink', 10, 2 );
カスタム投稿の ["rewrite"]["with_front"] を明示的に false にしないと、/news/ が、カスタム投稿のパーマリンクについてしまいますね。単に、"rewrite" => true とした場合、with_front は true として扱われます。
[パーマリンクを書き換える] が true の場合は、with_front を true / false をコントロール出来るラジオボタンがあっても良いかとは思ったりします。
@AtsushiA
rewrite の中の 'rewrite_slug' => false, ってこれ true と false で何が変わります?
@AtsushiA 変更版アップデートしましたんー
@kurudrive ありがとうございます!!確認しました!期待通りでございますm( )m
_|\○_ヒャッ ε=\_○ノ ホーウ!!
設定 > パーマリンクで /news/%postname%/ にすると /news/event/%postname%/ になってしまうため
設定画面のチェックボックスでええんちゃう?