Home › Forums › Front-end Issues › Radio Conditional; not working
Hi,
I have a custom field with a field name of “business_price_type” and 3 options:
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.
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”:
Here is a screenshot of how I set up the business price type custom field:
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.
The topic ‘Radio Conditional; not working’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.