1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WP ACF Selectで返り値Bothの出力

Posted at

返り値BothでValueもlabelもとりたいとき。
例えばValueをクラス名として、labelはそのまま表示みたいな。

公式docにあるものがなんかうまくいかなかったから備忘録。

方法

value : label

:の前後に半角スペース忘れない。
Valueは半角英数字のみ。

  1. カスタムフィールドで、値とラベルを入れてSelectを作る。返り値をBothにする。
  2. 出力するテンプレートでこう書く
templete.php

<?php //ループ内 ?>

<?php 
  $field = get_field('select', $post->ID); 
?>
<div class="<?php echo $field['value']; ?>">
  <?php echo $field['label']; ?>
</div>

これだけのことなんだけど苦労した・・・。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?