Support

Account

Home Forums Add-ons Flexible Content Field Conditional value display

Solved

Conditional value display

  • I am using the flexible content fields.

    What I want to do is echo something on the frontend only if the subfield has a value.

    I have no idea what is the correct PHP markup but in basic words something like below.

    If the_sub_field(‘mysubfield’); has a value show <div class=”mysubfield”>the_sub_field(‘mysubfield’);</div>

    Hope that makes sense=)

  • you need to use get_sub_field() to check a value. get_sub_field() returns a value and the_sub_field() echos the value.

    
    if (get_sub_field('mysubfield')) {
      ?>
        <div class="mysubfield"><?php the_sub_field('mysubfield'); ?></div>
      <?php 
    }
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Conditional value display’ is closed to new replies.