質問編集履歴
5
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,7 +54,14 @@
|
|
54
54
|
https://hogehoge.hoge/customer/voice
|
55
55
|
でアクセスアクセスすると問題なく表示される
|
56
56
|
|
57
|
+
10/20 12:05追記
|
58
|
+
ワードプレス管理画面のパーマーリンク設定の保存ボタンを押したところ
|
59
|
+
https://hogehoge.hoge/customer/voice.html/
|
60
|
+
となり
|
61
|
+
TOPページに飛ばされるようになり
|
62
|
+
また振り出しに戻ってしまいました・・・
|
57
63
|
|
64
|
+
|
58
65
|
新コード
|
59
66
|
```php
|
60
67
|
#バージョンアップ版
|
4
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -45,8 +45,26 @@
|
|
45
45
|
|
46
46
|
のようになり、404エラーのままで先に進めないです。
|
47
47
|
|
48
|
+
10/20 12:00追記
|
49
|
+
コードを見直して
|
50
|
+
https://hogehoge.hoge/customer/voice.html
|
51
|
+
を表示できるように改良できました
|
52
|
+
|
53
|
+
しかし、404エラーになってしまいます。
|
54
|
+
https://hogehoge.hoge/customer/voice
|
55
|
+
でアクセスアクセスすると問題なく表示される
|
56
|
+
|
57
|
+
|
48
58
|
新コード
|
49
59
|
```php
|
60
|
+
#バージョンアップ版
|
61
|
+
global $wp_rewrite;
|
62
|
+
$wp_rewrite->use_trailing_slashes=false;//最後のスラッシュ無し
|
63
|
+
$queryarg = 'customer&p=';//クエリ作成
|
64
|
+
$wp_rewrite->add_rewrite_tag('%customer%', '([^/]+)', $queryarg);
|
65
|
+
$customer_struct='/customer/%customer%.html';
|
66
|
+
$wp_rewrite->add_permastruct('customer', $customer_struct);
|
67
|
+
#旧
|
50
68
|
global $wp_rewrite;
|
51
69
|
$wp_rewrite->use_trailing_slashes=false;//最後のスラッシュ無し
|
52
70
|
$queryarg = 'post_type=customer&p=';//クエリ作成
|
3
修正追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,8 @@
|
|
12
12
|
投稿IDの番号と最後にスラッシュが付いて404エラーになってしまいました。
|
13
13
|
これをスラッグ.htmlで最後にスラッシュ無しで404エラーを回避するにはどうすればよいでしょうか??
|
14
14
|
|
15
|
+
|
16
|
+
旧コード
|
15
17
|
```php
|
16
18
|
add_action('init', 'myposttype_customer_rewrite');
|
17
19
|
function myposttype_customer_rewrite() {
|
@@ -33,4 +35,21 @@
|
|
33
35
|
$newlink = home_url(user_trailingslashit($newlink));
|
34
36
|
return $newlink;
|
35
37
|
}
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
上記コードはスラッグではなく、IDで表示する方法のようなので再度調べて新しくコードを追加
|
42
|
+
|
43
|
+
しかし、
|
44
|
+
https://hogehoge.hoge/%post_tag%/%postname%.html
|
45
|
+
|
46
|
+
のようになり、404エラーのままで先に進めないです。
|
47
|
+
|
48
|
+
新コード
|
49
|
+
```php
|
50
|
+
global $wp_rewrite;
|
51
|
+
$wp_rewrite->use_trailing_slashes=false;//最後のスラッシュ無し
|
52
|
+
$queryarg = 'post_type=customer&p=';//クエリ作成
|
53
|
+
$wp_rewrite->add_rewrite_tag('%post_tag%', '([^/]+)', $queryarg);
|
54
|
+
$wp_rewrite->add_permastruct('customer', '%post_tag%/%postname%.html', false);
|
36
55
|
```
|
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,8 +9,8 @@
|
|
9
9
|
https://memocarilog.info/wordpress/theme-custom/3909
|
10
10
|
下記のコードをfunctions.phpに追加したのですが
|
11
11
|
|
12
|
-
投稿IDの番号と最後にスラッシュが付いてしまいました。
|
12
|
+
投稿IDの番号と最後にスラッシュが付いて404エラーになってしまいました。
|
13
|
-
これをスラッグ.htmlで最後にスラッシュ無し
|
13
|
+
これをスラッグ.htmlで最後にスラッシュ無しで404エラーを回避するにはどうすればよいでしょうか??
|
14
14
|
|
15
15
|
```php
|
16
16
|
add_action('init', 'myposttype_customer_rewrite');
|
1
自己解決して次の課題
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
customerと言うカスタム投稿で
|
2
2
|
https://hogehoge.hoge/customer/voice.html
|
3
3
|
としたいのですが現状
|
4
|
-
https://hogehoge.hoge/customer/
|
4
|
+
https://hogehoge.hoge/customer/012.html/
|
5
5
|
となってしまいます。
|
6
6
|
|
7
7
|
下記サイトを参考に
|
8
8
|
https://webcre8tor.com/snippets/custom-post-type-url.html
|
9
9
|
https://memocarilog.info/wordpress/theme-custom/3909
|
10
10
|
下記のコードをfunctions.phpに追加したのですが
|
11
|
-
customerだけ致命的なエラーとなり先に進めない
|
12
|
-
このコードのどこが悪いのでしょうか?
|
13
11
|
|
12
|
+
投稿IDの番号と最後にスラッシュが付いてしまいました。
|
13
|
+
これをスラッグ.htmlで最後にスラッシュ無しにするにはどうすればよいでしょうか??
|
14
|
+
|
14
15
|
```php
|
15
16
|
add_action('init', 'myposttype_customer_rewrite');
|
16
17
|
function myposttype_customer_rewrite() {
|
@@ -24,7 +25,7 @@
|
|
24
25
|
add_filter('post_type_link', 'myposttype_customer_permalink', 1, 3);
|
25
26
|
function myposttype_customer_permalink($post_link, $id = 0, $leavename) {
|
26
27
|
global $wp_rewrite;
|
27
|
-
$post = &
|
28
|
+
$post = &get_post($id);
|
28
29
|
if ( is_wp_error( $post ) )
|
29
30
|
return $post;
|
30
31
|
$newlink = $wp_rewrite->get_extra_permastruct($post->post_type);
|