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> Link to comment https://forums.phpfreaks.com/topic/296424-drop-down-selector/ 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. Link to comment https://forums.phpfreaks.com/topic/296424-drop-down-selector/#findComment-1512327 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? Link to comment https://forums.phpfreaks.com/topic/296424-drop-down-selector/#findComment-1512328 Share on other sites More sharing options...
Ch0cu3r Posted May 20, 2015 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; ?> Link to comment https://forums.phpfreaks.com/topic/296424-drop-down-selector/#findComment-1512331 Share on other sites More sharing options...
humburger2015 Posted May 20, 2015 Author Share Posted May 20, 2015 Worked perfectly. Thank you so much! Link to comment https://forums.phpfreaks.com/topic/296424-drop-down-selector/#findComment-1512333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.