1

私はACFリピーターを使用してリストから結果を生成していますが、これはすべて正常に機能しています。しかし、リストの値を表示するのではなく、リストのラベルを表示したいのです。

コードは次のとおりです。

        <ul class="notifications-content">
            <?php while(has_sub_field('notification')):
                $house = get_sub_field('house');    
                $year  = get_sub_field('year');
                $date = DateTime::createFromFormat('Ymd', get_sub_field('date'));
                $newDate = date("D j F", strtotime($date->format('d-m-Y')));
                ?>
                <li class="<?php echo safe_url($house); ?> <?php echo $year; ?>">
                    <h2 class="black"><?php echo str_replace($replace, '', get_sub_field('message')); ?></h2>
                    <h3 class="interstatebold white uppercase"><?php echo $house; echo $year ? ", $year"  : ''; echo ' | '.$newDate; ?></h3>
                    <?php echo get_sub_field('urgent') ? '<div class="circle"></div>' : ''; ?>
                </li>
            <?php endwhile; ?>
        </ul>

ラベルを取得するにはどうすればよいですか?

4

3 に答える 3

0

これらの関数を介して渡すことで、フィールド値を呼び出すのと同じ方法で使用できます (functions.php に追加)。


function get_field_label($slug) {
    $field = get_field_object($slug); 
    return $field['label'];
}

使用法:

<?php echo get_field_label('field-slug'); ?>


function the_field_label($slug) {
    $field = get_field_object($slug); 
    echo $field['label'];
}

使用法:

<?php the_field_label('field-slug'); ?>


于 2016-01-20T18:55:43.630 に答える