Hi there,
Fantastic plugin and it’s been working a treat on many projects.
I have come across a simple problem of combining two fields into an if/else statement with one reliant on another and would love some assistance.
I have a radio field that has the values “yes” and “no” and then a text field that a user can input a value.
Here is the code”
<?php if (get_field('homepage-banner-overlay') == 'no') { ?>
<div class="homepage-banner-container">
<?php } elseif (get_field('homepage-banner-overlay') == 'yes') { ?>
<div class="homepage-banner-container banner-overlay">
<?php } elseif (get_field('homepage-banner-overlay') == 'yes' && get_field('homepage-banner-overlay-colour')) { ?>
<div class="homepage-banner-container banner-overlay" style="background:red;">
<?php } ?>
Everything works except for the last elseif which I would like to show if the field ‘homepage-banner-overlay-colour’ has a value in it.
Your help is much appreciated.
Cheers
You need to adjust the second if statement because if you’re 3rd if is true then the 2nd is always true. Do the more specific one first.
<?php if (get_field('homepage-banner-overlay') == 'no') { ?>
<div class="homepage-banner-container">
<?php } elseif (get_field('homepage-banner-overlay') == 'yes' && get_field('homepage-banner-overlay-colour')) { ?>
<div class="homepage-banner-container banner-overlay" style="background:red;">
<?php } elseif (get_field('homepage-banner-overlay') == 'yes') { ?>
<div class="homepage-banner-container banner-overlay">
<?php } ?>
Works a treat, I thought it would be simple.
Thanks for your help, have a great weekend.