Support

Account

Home Forums Front-end Issues Radio Conditional; not working

Solved

Radio Conditional; not working

  • Hi,

    I have a custom field with a field name of “business_price_type” and 3 options:

    • price : Price
    • pur : Provided Upon Request
    • none : None

    I have the following code set up on my site:

    if (get_field('business_price_type') == 'price') {
                        echo '<span class="ListingPrice">$' . number_format($price, 0, '', ',') . '</span>';
                      } elseif (get_field('business_price_type') == 'pur') {
                        echo '<span class="ListingPrice">Price provided upon request</span>';
                      }

    If a listing has a brice, it displays fine. If it has the “Provided Upon Request” option selected, nothing displays. Please advise what I am doing wrong. Thank you.

  • What version of ACF are you using?

  • I ask because the code looks right, in ACF5.5 you can specify the return type. But now that I look at this it does not explain it either. So the question is, what are you getting?

    
    $type = get_field('business_price_type');
    // echo the value to test and see what you're getting
    echo $type;
    if ($type == 'price') {
      echo '<span class="ListingPrice">$' . 
            number_format($price, 0, '', ',') . '</span>';
    } elseif ($type == 'pur') {
      echo '<span class="ListingPrice">Price provided upon request</span>';
    }
    
  • Here is a screenshot of a listing that should have “Price provided upon request”:
    Listing that should have 'Price provided upon request'

    Here is a screenshot of how I set up the business price type custom field:
    Business Price Type Setup

  • If you know for sure that you’ve selected a value for every post then I’m lost as to why you’d be seeing these results.

    The things that come to mind are
    1) Not all values are set
    2) There is another field somewhere on this post type that’s using the same name, you could try changing the field name
    3) You’re getting a value from a different post or some unknown location, this can happen if you are not inside “The Loop” when getting the value

  • I had wrapped the whole bit in another conditional that did not reference the state with
    if (get_field('business_price_type') == 'price')

    I lost sight of the forest for the tree.
    Thanks for your help.

  • Sometimes that happens, glad you found it.

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Radio Conditional; not working’ is closed to new replies.