Title: 同じ値をもつカスタムフィールドのデータが複数あった場合、1つ目のカス
Last modified: 2016年7月30日

---

# 同じ値をもつカスタムフィールドのデータが複数あった場合、1つ目のカス

 *  解決済 [cloche](https://ja.wordpress.org/support/users/cloche/)
 * (@cloche)
 * [13年、 5ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e5%80%a4%e3%82%92%e3%82%82%e3%81%a4%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%95%e3%82%a3%e3%83%bc%e3%83%ab%e3%83%89%e3%81%ae%e3%83%87%e3%83%bc%e3%82%bf%e3%81%8c%e8%a4%87%e6%95%b0/)
 * 色々と試したのですが、うまく動かないのでご教授頂けたら幸いです。
 * 下記構造のカスタム投稿があり
    ・Title ・content ・カスタムフィールド（年度）
 * 下記の様に同じカスタムフィールド（年度）のデータが複数あった場合、最初の1つのみ
   表示させる方法はありますでしょうか？
 * データ———————————-
    title1　content①　年度① title2　content②　年度① title3　content
   ③　年度① title4　content①　年度② title5　content②　年度② title6　content③　年度
   ② 表示させたい形式———————————- <h3>年度①</h3> content① content② content③ <h3>
   年度②</h3> content① content② content③ ———————————-
 * 下記コードで年度①は取得できています。
    ——————————————————————– <?php $cnt = 1;?
   >
 * <?php if(have_posts()): ?>
    <?php while(have_posts()):the_post(); ?>
 * <!– title –>
 * <?php if(post_custom(‘年度’) == ‘2013年（平成25年）3月期’) : ?>
    <?php if ($cnt
   == 1) : ?> <h3 id=”mar”> <?php echo post_custom(‘年度’); ?> </h3> <?php $cnt+
   +;?>
 * <?php endif; ?>
    <?php endif; ?>
 * <!– hyouji –>
    <dl class=”dl1″> <dt> <?php echo post_custom(‘日付’); ?> </dt>
   <dd> <?php the_content() ?> </dd> </dl>
 * <?php endwhile; else: ?>
 * ページが存在しません
 * <?php endif; ?>
    <?php wp_reset_query(); ?> ——————————————————————–

2件の返信を表示中 - 1 - 2件目 (全2件中)

 *  [pluto1234](https://ja.wordpress.org/support/users/pluto1234/)
 * (@pluto1234)
 * [13年、 5ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e5%80%a4%e3%82%92%e3%82%82%e3%81%a4%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%95%e3%82%a3%e3%83%bc%e3%83%ab%e3%83%89%e3%81%ae%e3%83%87%e3%83%bc%e3%82%bf%e3%81%8c%e8%a4%87%e6%95%b0/#post-161187)
 *     ```
       <?php $save_nendo = ''; ?>
       <?php if(have_posts()): ?>
       <?php while(have_posts()):the_post(); ?>
   
         <!-- title -->
         <?php $nendo = post_custom('年度'); ?>
         <?php if($nendo != $save_nendo) : ?>
           <h3 id="mar"><?php echo $nendo; ?></h3>
         <?php endif; ?>
         <?php $save_nendo = $nendo; ?>
   
         <!-- hyouji -->
               :
               :
       ```
   
 * ※ <h3 id=”mar”> だと、同じidが何度も出現します。
 *  トピック投稿者 [cloche](https://ja.wordpress.org/support/users/cloche/)
 * (@cloche)
 * [13年、 5ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e5%80%a4%e3%82%92%e3%82%82%e3%81%a4%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%95%e3%82%a3%e3%83%bc%e3%83%ab%e3%83%89%e3%81%ae%e3%83%87%e3%83%bc%e3%82%bf%e3%81%8c%e8%a4%87%e6%95%b0/#post-161189)
 * pluto1234様
 * ご教授ありがとうございます。
    おかげで期待する動作になりました。

2件の返信を表示中 - 1 - 2件目 (全2件中)

 トピック「同じ値をもつカスタムフィールドのデータが複数あった場合、1つ目のカス」
には新たに返信することはできません。

## タグ

 * [カスタムフィールド](https://ja.wordpress.org/support/topic-tag/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%95%e3%82%a3%e3%83%bc%e3%83%ab%e3%83%89/)

 * フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2件の返信
 * 2人の参加者
 * 最後の返信者: [cloche](https://ja.wordpress.org/support/users/cloche/)
 * 最後の活動: [13年、 5ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e5%80%a4%e3%82%92%e3%82%82%e3%81%a4%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%95%e3%82%a3%e3%83%bc%e3%83%ab%e3%83%89%e3%81%ae%e3%83%87%e3%83%bc%e3%82%bf%e3%81%8c%e8%a4%87%e6%95%b0/#post-161189)
 * 状態: 解決済

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
