カスタムフィールドグループをCSVインポートする

この記事は公開日より9年以上経過しているため、現在の内容と異なる可能性があります。

CSVインポートでは、エントリーの情報と、カスタムフィールドの値を登録することができます。この時にカスタムフィールドグループの値をCSVインポートする方法について解説します。

カスタムフィールドの値をインポートする場合

カスタムフィールドの記述

<input type="text" name="meta_keywords" value="{meta_keywords}" class="acms-form-width-3quarters" />
<input type="hidden" name="field[]" value="meta_keywords" />

CSVファイルの記述

entry_category_id,entry_title,meta_keywords
"5","CSVインポートテスト","metaデータ"

カスタムフィールド名「meta_keywords」をCSVインポートする場合の例です。

カスタムフィールドグループの値をインポートする場合

カスタムフィールドグループの記述

<h3>カスタムフィールドグループ</h3>
<div class="acms-table-responsive">
<table class="js-fieldgroup-sortable">
 <thead>
 <tr>
  <th> </th>
  <th>タイトル</th>
  <th>データ</th>
  <th>削除</th>
 </tr>
 </thead>
 <!-- BEGIN customFieldGroup:loop -->
 <tr class="sortable-item">
  <td class="item-handle"><img width="17" height="17" class="arrowHandle" src="/images/admin_arrow_vertical.gif" /></td>
  <td>
   <input type="text" name="cfgTitle[{i}]" value="{cfgTitle}" size="40" style="width:300px" placeholder="タイトル" />
  </td>
  <td>
   <input type="text" name="cfgData[{i}]" value="{cfgData}" size="40" style="width:300px" placeholder="データ" />
  </td>
  <td><input type="button" class="item-delete acms-btn-admin acms-btn-admin-danger" value="削除" /></td>
 </tr>
 <!-- END customFieldGroup:loop -->
 <tr class="sortable-item item-template">
  <td class="item-handle"><img width="17" height="17" class="arrowHandle" src="/images/admin_arrow_vertical.gif" /></td>
  <td>
   <input type="text" name="cfgTitle[]" value="" size="40" style="width:300px" placeholder="タイトル" />
  </td>
  <td>
   <input type="text" name="cfgData[]" value="" size="40" style="width:300px" placeholder="データ" />
  </td>
  <td><input type="button" class="item-delete acms-btn-admin acms-btn-admin-danger" value="削除" /></td>
 </tr>
 <tfoot>
  <tr>
   <td colspan="4">
    <input type="button" class="item-insert acms-btn-admin" value="追加" style="width:100px" />
    <input type="hidden" class="item-max" value="4" />
   </td>
  </tr>
 </tfoot>
</table>
</div>
<input type="hidden" name="@customFieldGroup[]" value="cfgTitle" />
<input type="hidden" name="field[]" value="cfgTitle" />
<input type="hidden" name="@customFieldGroup[]" value="cfgData" />
<input type="hidden" name="field[]" value="cfgData" />
<input type="hidden" name="field[]" value="@customFieldGroup" />

CSVファイルの記述

entry_category_id,entry_title,meta_keywords,@customFieldGroup[1],@customFieldGroup[2],cfgTitle[1],cfgData[1],cfgTitle[2],cfgData[2]
"5","CSVインポートテスト","metaデータ","cfgTitle","cfgData","a01","a02","b01","b02"

カスタムフィールドグループ名「customFieldGroup」をCSVインポートする場合の例です。
上記の例では、グループ内の変数は2個「cfgTitle」「cfgData」ですので、フィールド名は「@customFieldGroup[1]」「@customFieldGroup[2]」の2個を用意し、その値は「cfgTitle」「cfgData」としています。これはCSVで登録するエントリーの複数件あっても、全て「cfgTitle」「cfgData」とします。
グループを2つ登録している場合のCSVの書き方です。cfgTitle[1],cfgData[1]が1グループ目、cfgTitle[2],cfgData[2]が2グループ目となります。
CSVで登録するエントリーの中で一番多いグループ数に合わせてCSVのフィールドを用意してください。

同じタグ付けがされている記事