ど素人から毛を生やす。<延>

カスタム投稿のカテゴリに都道府県名を入れたい

Web > WordPress > カスタム投稿 2014年8月20日(最終更新:10年以上前)

2014年8月20日に作成されたページです。
情報が古かったり、僕が今以上のど素人だった頃の記事だったりする可能性があります。

どもです。
ほんのり頭痛気味の餅。です。

祝・ルミエルレガシィ発売(゚∀゚)
早く手に取りたくて仕方ないですね(゚∀゚)(゚∀゚)

取り敢えずWordPress。

企業サイトWordPress化とかしていますと、たまに出てくる「都道府県カテゴリ」。

いちいち手打ちでやるのも面倒……
どころか、カスタム投稿で複数に設定となると、面倒を通り越し発狂したくなります。

ということで調べてみたところ、やはり先人様の記事が。
なるほど(゚∀゚)インポートを使えば良いのですな。

……ところで、カスタム投稿についてはどうすれば良いのかね?

というわけでカスタム投稿版都道府県XML、作ってみました。


	<wp:term><wp:term_id>101</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>area</wp:term_slug><wp:term_parent></wp:term_parent><wp:term_name><![CDATA[都道府県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>102</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>hokkaido</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[北海道]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>103</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>aomori</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[青森県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>104</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>iwate</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[岩手県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>105</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>miyagi</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[宮城県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>106</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>akita</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[秋田県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>107</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>yamagata</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[山形県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>108</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>fukushima</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[福島県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>109</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>ibaraki</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[茨城県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>110</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>totigi</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[栃木県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>111</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>gunma</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[群馬県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>112</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>saitama</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[埼玉県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>113</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>chiba</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[千葉県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>114</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>tokyo</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[東京都]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>115</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>kanagawa</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[神奈川県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>116</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>nigata</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[新潟県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>117</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>toyama</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[富山県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>118</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>ishikawa</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[石川県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>119</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>fukui</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[福井県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>120</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>yamanashi</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[山梨県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>121</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>nagano</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[長野県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>122</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>gifu</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[岐阜県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>123</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>shizuoka</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[静岡県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>124</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>aichi</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[愛知県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>125</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>mie</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[三重県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>126</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>shiga</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[滋賀県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>127</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>kyouto</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[京都府]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>128</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>osaka</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[大阪府]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>129</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>hyogo</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[兵庫県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>130</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>nara</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[奈良県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>131</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>wakayama</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[和歌山県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>132</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>tottori</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[鳥取県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>133</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>shimane</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[島根県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>134</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>okayama</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[岡山県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>135</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>hiroshima</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[広島県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>136</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>yamaguchi</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[山口県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>137</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>tokushima</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[徳島県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>138</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>kagawa</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[香川県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>139</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>ehime</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[愛媛県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>140</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>kochi</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[高知県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>141</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>fukuoka</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[福岡県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>142</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>saga</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[佐賀県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>143</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>nagasaki</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[長崎県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>144</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>kumamoto</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[熊本県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>145</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>oita</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[大分県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>146</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>miyazaki</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[宮崎県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>147</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>kagoshima</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[鹿児島県]]></wp:term_name></wp:term>
	<wp:term><wp:term_id>148</wp:term_id><wp:term_taxonomy>タクソノミー名</wp:term_taxonomy><wp:term_slug>okinawa</wp:term_slug><wp:term_parent>area</wp:term_parent><wp:term_name><![CDATA[沖縄県]]></wp:term_name></wp:term>

「タクソノミー名」のところを一括置換でおkです。誤字ってても責任は取らぬ(゚∀゚)

インポートするときは、一度現在のWordPressをエクスポートして、
カテゴリが入っているところの後ろにくっつけてしまえば大丈夫です。

term_idは101からスタートにしてあるので、
既に100以上のカテゴリIDを作ってしまっている場合はここも一括置換。
「<wp:term_id>1」→「<wp:term_id>2」みたいな感じで置換してしまえばおk。

また、今回の僕の件のように複数のカスタム投稿に設置する場合、WordPressはカテゴリのスラッグの重複がダメなので、こちらも一括置換で対策してしまいましょう。
「<wp:term_slug>」→「<wp:term_slug>a_」みたいな対策でおkでしょう。

 

この記事は役に立ちましたか?
  • _(:3」∠)_ 面白かった (0)
  • (・∀・) 参考になった (0)
  • (`・ω・´) 役に立った (0)