回答編集履歴

1

追記

2021/09/24 05:14

投稿

tabuu
tabuu

スコア2449

test CHANGED
@@ -4,4 +4,122 @@
4
4
 
5
5
 
6
6
 
7
+ (追記)
8
+
9
+ 下記のようにコードを修正すれば問題ないと思いますが同一名称のカスタム投稿タイプは
10
+
11
+ 設定できません。例ではarticle2としました。
12
+
13
+
14
+
15
+ ```PHP
16
+
17
+ function add_custom_post() {
18
+
19
+ register_post_type(
20
+
21
+ 'article',
22
+
23
+ array(
24
+
25
+ 'label'=> '記事1',
26
+
27
+ 'labels' => array(
28
+
29
+ 'menu_name' => '記事1'
30
+
31
+ ),
32
+
33
+ 'public' => true,
34
+
35
+ 'query_var' => true,
36
+
37
+ 'hierarchical' => false,
38
+
39
+ 'rewrite' => array('slug' => 'article'),
40
+
41
+ 'has_archive' => true,
42
+
43
+ 'show_in_rest' => true,
44
+
45
+ 'supports' => array(
46
+
47
+ 'title',
48
+
49
+ 'editor',
50
+
51
+ 'thumbnail',
52
+
53
+ 'excerpt',
54
+
55
+ 'author'
56
+
57
+ )
58
+
59
+ )
60
+
61
+ );
62
+
63
+ register_taxonomy_for_object_type('category', 'article');
64
+
65
+ register_taxonomy_for_object_type('post_tag', 'article');
66
+
67
+
68
+
69
+ register_post_type(
70
+
71
+ 'article2',
72
+
73
+ array(
74
+
75
+ 'label'=> '記事2',
76
+
77
+ 'labels' => array(
78
+
79
+ 'menu_name' => '記事2'
80
+
81
+ ),
82
+
83
+ 'public' => true,
84
+
85
+ 'query_var' => true,
86
+
87
+ 'hierarchical' => false,
88
+
89
+ 'rewrite' => array('slug' => 'article2'),
90
+
91
+ 'has_archive' => true,
92
+
93
+ 'show_in_rest' => true,
94
+
95
+ 'supports' => array(
96
+
97
+ 'title',
98
+
99
+ 'editor',
100
+
101
+ 'thumbnail',
102
+
103
+ 'excerpt',
104
+
105
+ 'author'
106
+
107
+ )
108
+
109
+ )
110
+
111
+ );
112
+
113
+ register_taxonomy_for_object_type('category', 'article2');
114
+
115
+ register_taxonomy_for_object_type('post_tag', 'article2');
116
+
117
+ }
118
+
119
+ add_action('init', 'add_custom_post');
120
+
121
+ ```
122
+
123
+
124
+
7
125
  ※質問される際はソースコードのインデントを揃えて見やすくしたり、エラーの内容も記述されると回答が付きやすくなりますので次回からお願いします。