Home Forums General Issues Values vs. Labels


Values vs. Labels

  • I’ve been reading through the documentation and am not seeming to find a solution. If using this example as what my setup would be like ( I’m trying to get the field value to display – not the label. What I mean specifically, in referencing the example from above, I would want the php to generate “col_1” and not “Column 1”. Hope that makes sense. What is the correct code?

    • Elliot

    • August 20, 2013 at 2:59 pm

    Hi @kikimarie1234

    When creating your field, enter the choices like this:

    col_1 : Column 1

    Then in your code, load the value like this:

    $value = get_field('field_name');
  • Doesn’t work. Still returning the label.

    Here is what my code looks like:

    $the_query = new WP_Query( $args ); ?>
    	<?php if( $the_query->have_posts() ): ?>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		$value = get_field('industry_subsector'); 
    		<li id="<?php echo $value; ?>">
    			<?php the_field('industry_subsector'); ?>
    	<?php endwhile; ?>
    <?php endif; ?>

    Here is what I get…

    	<li id="Building Products">Building Products</li>
    	<li id="General Industrial">General Industrial</li>
    	<li id="Specialty Chemicals">Specialty Chemicals</li>
    	<li id="Measurement & Controls">Measurement & Controls</li>
    	<li id="Automotive">Automotive</li>

    My field choices look like this:

    automotive : Automotive
    building_products : Building Products
    measurement_controls : Measurement & Controls
    paper_packaging : Paper/Packaging
    general_industrial : General Industrial
    specialty_chemicals : Specialty Chemicals

    I want it to look like this:

    	<li id="building_products">Building Products</li>
    	<li id="general_industrial">General Industrial</li>
    	<li id="specialty_chemicals">Specialty Chemicals</li>
    	<li id="measurement_controls">Measurement & Controls</li>
    	<li id="automotive">Automotive</li>

    What am I doing wrong?

    • Elliot

    • August 21, 2013 at 2:53 pm

    Hi @kikimarie1234

    Can you please check your DB and see what value is being saved for your $field_name and $post_id?

    I am 100% sure that the select field will save the value, not the label.

    Do you have a custom filter which is modifying the value?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

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.