Support

Account

Home Forums Front-end Issues checking the value of a field

Helping

checking the value of a field

  • Hi, I created a custom field with type ‘radio’ called ‘transaction_type’ with two values: ‘buy’ & ‘sell’.

    However, the following code is not working:

     <?php if (get_field('transaction_type') = 'buy') { ?>
        <td><?php the_field('purchase_price'); ?></td>
      <?php } elseif (get_field('transaction_type') = 'sell') { ?>
        <td><?php the_field('sell_price'); ?></td>
      <?php } ?>

    ‘purchase_price’ & ‘sell_price’ are another two custom fields. They do not display on the front end. Other custom fields are displaying fine.

    Help appreciated.

  • Hi @srd

    I believe that you will need to change the equality operator to == like so:

    <?php if (get_field('transaction_type') == 'buy') { ?>
        <td><?php the_field('purchase_price'); ?></td>
      <?php } elseif (get_field('transaction_type') == 'sell') { ?>
        <td><?php the_field('sell_price'); ?></td>
      <?php } ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘checking the value of a field’ is closed to new replies.