Support

Account

Home Forums General Issues How to convert a text value from a field to a numerical value within a Variable?

Helping

How to convert a text value from a field to a numerical value within a Variable?

  • Hi,

    I am new to PHP and have limited experience as this is my first project. I am creating an audit using a custom post type and ACF.

    within my post template which will be the front end “report” I need to show a % score for the audit. Each audit question is answered yes or no. Example field name is q1_answer

    I have the following code which looks at field q1_answer and if it is a yes displays a 1, however, I need the 1 to be the value of the variable so I can use it in my overall score calculation.

    <?php if (get_field('q1_answer') == 'Yes') {
              echo '1';
            } ?>
  • Hi @lee-harvey

    I am not sure that I have fully understood the description, is this what you are after?

    <?php if (get_field('q1_answer') == 'Yes') {
              $value = "1";
            } ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to convert a text value from a field to a numerical value within a Variable?’ is closed to new replies.