WordPressでカスタム投稿タイプpotato
のパーマリンクだけランダムにしたいと思うのですが、下記では全ての投稿がランダムになってしまいます。
カスタム投稿タイプの指定でどこが間違っているのでしょうか?
php
1function potato_slug( $data , $postarr ) { 2 3 if ($data['post_type'] == 'potato') { //potatoだけ 4 5 $str = array_merge(range('a', 'z'), range('0', '9'), range('A', 'Z"')); 6 $r_str = null; 7 8 for ($i = 0; $i < 12; $i++) { 9 $r_str .= $str[rand(0, count($str))]; 10 } 11 12 if ( ! in_array( $data['post_status'], array( 'trash', 'auto-draft' ) ) ) { 13 $data['post_status'] = 'publish'; 14 $data['post_name'] = $r_str; 15 } 16 17 } 18 return $data; 19 20} 21add_action( 'wp_insert_post_data', 'potato_slug', 99, 2 );
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/25 05:34
2018/09/25 06:18