vektor-inc / vk-all-in-one-expansion-unit

wordpress plugin of powerful support
https://ja.wordpress.org/plugins/vk-all-in-one-expansion-unit/
GNU General Public License v2.0
7 stars 1 forks source link

[ カスタム投稿タイプマネージャー ] リライトをオフにするオプションを追加して欲しい by あんどうさん #1066

Closed kurudrive closed 6 months ago

kurudrive commented 7 months ago

設定 > パーマリンクで /news/%postname%/ にすると /news/event/%postname%/ になってしまうため

設定画面のチェックボックスでええんちゃう?

kurudrive commented 6 months ago

https://gist.github.com/AtsushiA/1e45d176200f70dd23e24c7ebef36957?fbclid=IwAR32wi2rEEF6hhONf-4fDdt6S7X2V_RnX6ZOtnwZr-FX7DRO9ETWQqv0a4Y

kurudrive commented 6 months ago

@AtsushiA

スクリーンショット 2024-03-05 1 58 46
AtsushiA commented 6 months ago

@kurudrive お手数をおかけしてすみません。 パーマリンクの書き換え (任意) 設定を "パーマリンクを書き換えない"にすると Custom Post Type Permalinksでパーマリングの変更から該当のポストタイプのパーマリンクが変更できなくなってしまうのです

https://example.com/?[postype]=test-[postname] 固定になってしまう

kurudrive commented 6 months ago

@AtsushiA 確認ありがとうございます。

まず、従来の設定の場合、event のカスタム投稿タイプの場合、Custom Post Type Permalinks で変更しようとすると http://localhost:8888/event/ 以下を変更可能

また、マスターのパーマリンクを /news/%postname%/ に変更すると http://localhost:8888/news/event/ 以下を変更可能

という状態になります。

これをどう形式に変更できれば要件クリアでしょうか?

news も event も含めずに自由に変更できるという事ですか(・w・?

AtsushiA commented 6 months ago

@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 );
torounit commented 6 months ago

カスタム投稿の ["rewrite"]["with_front"] を明示的に false にしないと、/news/ が、カスタム投稿のパーマリンクについてしまいますね。単に、"rewrite" => true とした場合、with_front は true として扱われます。

https://github.com/WordPress/wordpress-develop/blob/3c2a87e2aeb71d20f72b4f94b15e1caf803e8f21/src/wp-includes/class-wp-post-type.php#L632-L634

[パーマリンクを書き換える] が true の場合は、with_front を true / false をコントロール出来るラジオボタンがあっても良いかとは思ったりします。

kurudrive commented 6 months ago

@AtsushiA

rewrite の中の 'rewrite_slug' => false, ってこれ true と false で何が変わります?

kurudrive commented 6 months ago

@AtsushiA 変更版アップデートしましたんー

AtsushiA commented 6 months ago

@kurudrive ありがとうございます!!確認しました!期待通りでございますm( )m

kurudrive commented 6 months ago

_|\○_ヒャッ ε=\_○ノ ホーウ!!