Home › Forums › General Issues › Field Type Select Echo Value & Label?
Hi guys,
First off. This plugin is awesome. Seriously powerful.
I’m using the select custom field to allow a user to pick a drop down option and for that to then be echo’d out in the theme. This works perfectly.
However Currently the options I have set are:
fabric : Fabric
ministry-of-sound : Ministry Of Sound
mahiki : Mahiki
moustache-bar : Moustache Bar
But I would like it to be:
fabric : Fabric
ministry-of-sound : Ministry Of Sound
mahiki : Mahiki
moustache-bar : Moustache Bar
This causes some issues and doesn’t echo the way I would hope as it seems to get trimmed.
I’m currently getting my code to echo out the Value of the Select Custom field with the following:
if ( is_single() ) {
$cats = wp_get_post_categories($posts[0]->ID);
$first_cat = '';
if ($cats) {
$first_cat = $cats[0];}
if ($first_cat == 4 ) {
echo 'This nightclub is CLOSED!';}
elseif ($first_cat == 29) {
echo 'This is an Event!<br>';
$eventstart = get_field('eventstart');
$eventend = get_field('eventend');
$ticketprice = get_field('ticketprice');
$minage = get_field('minage');
$neareststation = get_field('neareststation');
$venue = get_field('venue');
echo 'The Event Begins - ' . $eventstart;
echo '<br>The Event Ends - ' . $eventend;
echo '<br>Ticket Price - ' . $ticketprice;
echo '<br>Minimum Age - ' . $minage;
echo '<br>Nearest Station - ' . $neareststation;
echo '<br>Venue - ' . $venue;
}
elseif ($first_cat == 3) {
echo 'This nightclub is OPEN!';}
elseif ($first_cat == 2) {
echo 'This is a guide!';}
elseif ($first_cat == 28) {
echo 'Cheap As Chips!';}
elseif ($first_cat == 27) {
echo 'Average Spend!';}
elseif ($first_cat == 26) {
echo 'Big Spender!';}
}
}
?>
How do I also get it to echo the Label OR is there a workaround without php?
Many thanks in advance for your time,
Bowser

I dont really get what you’re after but to get both the value and the label of the field you can use http://www.advancedcustomfields.com/resources/functions/get_field_object/
The topic ‘Field Type Select Echo Value & Label?’ 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.