humburger2015 Posted May 20, 2015 Share Posted May 20, 2015 I have a dropdown selector for languages. It was creating using the custom fields in WordPress. There will be some fields that i need to leave blank but the blank fields still show up in the drop down selector. Is there a PHP "if" statement that someone can supply me that would hide blank fields in the drop down. For example, 'if' character count is less than 1 then hide field?Here is the code I currently have: <!-- Countries Select Box --> <select id="country_selector"> <?php foreach ($footer["countries"] as $country) : ?> <option value="<?= $country['english'];?>" data-int-url="<?= $country['url'];?>" data-int-img="<?= $country['img'];?>" data-int-cc="<?= $country['cc'];?>"> <?= $country['native'];?> </option> <?php endforeach; ?> </select> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted May 20, 2015 Share Posted May 20, 2015 Yes. Look using empty as the condition for the if. Although a better alternative would be to modify your query so it does not return values which are empty. Quote Link to comment Share on other sites More sharing options...
humburger2015 Posted May 20, 2015 Author Share Posted May 20, 2015 Thank you, Ch0cu3r. Would you be able to show me how the empty condition would be applied to this code? Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted May 20, 2015 Solution Share Posted May 20, 2015 I assume its the native value you want to check is not empty? <?php foreach ($footer["countries"] as $country): if(!empty($country['native'])): ?> <option value="<?= $country['english'];?>" data-int-url="<?= $country['url'];?>" data-int-img="<?= $country['img'];?>" data-int-cc="<?= $country['cc'];?>"> <?= $country['native'];?> </option> <?php endif; endforeach; ?> Quote Link to comment Share on other sites More sharing options...
humburger2015 Posted May 20, 2015 Author Share Posted May 20, 2015 Worked perfectly. Thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.