サポート » プラグイン » アドバンスカスタムフィールドの繰り返しフィールドについて

  • こんばんは。
    アドバンスカスタムフィールドの繰り返しフィールドを使用しているのですが、複数あるサブフィールドの中で特定のサブフィールドが未入力の場合は表示しないようにしたいのですが、出来ずにつまづいています。

    <div id=”tab-1″>
    <?php if(get_field(‘fields_group’)): ?>
    <?php while(has_sub_field(‘fields_group’)): ?>
    <table id=”group”>
    <tbody>
    <tr>
    <th>サブフィールド①</th>
    <td><?php the_sub_field(’sub_field01′); ?></td>
    </tr>
    <tr>
    <th>サブフィールド②</th>
    <td><?php the_sub_field(‘sub_field02’); ?></td>
    </tr>
    <tr>
    <th>サブフィールド③</th>
    <td><?php the_sub_field(‘sub_field03’); ?></td>
    </tr>
    </tbody>
    </table>
    <? endwhile; ?>
    </div>
    <?php endif; ?>

    例えば上の様な構成でサブフィールド②の<?php the_sub_field(‘sub_field02’); ?>の部分が未入力の場合はサブフィールド②の<tr></tr>の部分ごと非表示にしたいと思っています。

    どなたかご教授いただけると幸いです。

    よろしくお願いいたします。

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • モデレーター Daisuke Takahashi

    (@extendwings)

    has_sub_field()関数は使えませんか?

    トピック投稿者 melloncollie

    (@melloncollie)

    Daisuke Takahashiさま

    ありがとうございます。

    has_sub_field()関数ですね。

    トライしてみます!

    トピック投稿者 melloncollie

    (@melloncollie)

    すいません。

    下の様なコードにしたら、未入力の場合は表示されなくなりましたが、今度は入力しても表示されないようになってしまいました。

    <div id=”tab-1″>
    <?php if(get_field(‘fields_group’)): ?>
    <?php while(has_sub_field(‘fields_group’)): ?>
    <table id=“fields_group”>
    <tbody>
    <tr>
    <th>サブフィールド①</th>
    <td><?php the_sub_field(’sub_field01′); ?></td>
    </tr>
    <?php if( get_sub_field(‘fields_group’) ): ?>
    <?php while(has_sub_field(‘fields_group’)): ?>
    <tr>
    <th>サブフィールド②</th>
    <td><?php $variable = get_sub_field(‘sub_field02’); ?></td>
    </tr>
    <? endwhile; ?>
    <?php endif; ?>
    <tr>
    <th>サブフィールド③</th>
    <td><?php the_sub_field(‘sub_field03’); ?></td>
    </tr>
    </tbody>
    </table>
    <? endwhile; ?>
    </div>
    <?php endif; ?>

    書き方が間違っているのでしょうか?

    よろしくお願いいたします。

    トピック投稿者 melloncollie

    (@melloncollie)

    すいません。
    下のコードで自己解決しました。

    <div id=”tab-1″>
    <?php if(get_field(‘fields_group’)): ?>
    <?php while(has_sub_field(‘fields_group’)): ?>
    <table id=“fields_group”>
    <tbody>
    <tr>
    <th>サブフィールド①</th>
    <td><?php the_sub_field(’sub_field01′); ?></td>
    </tr>
    <?php if( get_sub_field(‘sub_field02’)): ?>
    <tr>
    <th>サブフィールド②</th>
    <td><?php the_sub_field(‘sub_field02’); ?></td>
    </tr>
    <?php endif; ?>
    <tr>
    <th>サブフィールド③</th>
    <td><?php the_sub_field(‘sub_field03’); ?></td>
    </tr>
    </tbody>
    </table>
    <? endwhile; ?>
    </div>
    <?php endif; ?>

    Daisuke Takahashiさま
    ありがとうございました。

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • トピック「アドバンスカスタムフィールドの繰り返しフィールドについて」には新たに返信することはできません。