Title: Output Select values
Last modified: August 24, 2016

---

# Output Select values

 *  Resolved [Anastasia Che](https://wordpress.org/support/users/anastasia-che/)
 * (@anastasia-che)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/)
 * Hi!
    Thank you so much for your plugin!
 * I’m trying to output value of single-choice select.
    I’m using this code for 
   it:
 *     ```
       <?php
       $values = CFS()->get('format_name');
       foreach ($values as $value => $label) {
            echo $value;
       }
       ?>
       ```
   
 * It gives me:
    `Warning: Invalid argument supplied for foreach() in (website address
   here)/loop-short2.php on line 21` Line 21 – is the one with start of foreach 
   cycle.
 * Can you please help me to figure out what I’m doing wrong?
 * Thank you!
 * [https://wordpress.org/plugins/custom-field-suite/](https://wordpress.org/plugins/custom-field-suite/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Matt Gibbs](https://wordpress.org/support/users/mgibbs189/)
 * (@mgibbs189)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030941)
 * You might need to make sure `$values` contains something.
 *     ```
       <?php
       $values = CFS()->get( 'format_name' );
       if ( ! empty( $values ) ) {
           foreach ( $values as $value => $label ) {
               echo $value;
           }
       }
       ?>
       ```
   
 *  Thread Starter [Anastasia Che](https://wordpress.org/support/users/anastasia-che/)
 * (@anastasia-che)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030946)
 * No, it doesn’t help, sorry. 🙁
    In this case nothing outputs. But I have non-
   empty values there which I need to output. 🙁
 *  Thread Starter [Anastasia Che](https://wordpress.org/support/users/anastasia-che/)
 * (@anastasia-che)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030947)
 * This time I’m trying to output chosen value with the following code:
 *     ```
       <?php
       $values = CFS()->get( 'step_color' );
       if ( ! empty( $values ) ) {
           foreach ( $values as $value => $label ) {
               echo $value;
           }
       }
       ?>
       ```
   
 * but nothing happens.
 * One more question.
    If I want to output value of option, not it’s label, should
   I use **$value => $val **instead of **$value => $label**?
 * Thanks!
 *  Plugin Author [Matt Gibbs](https://wordpress.org/support/users/mgibbs189/)
 * (@mgibbs189)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030979)
 *     ```
       $values = CFS()->get( 'step_color' );
       var_dump( $values );
       ```
   
 * … will show you what data you have to work with. If it’s an array, then you’ll
   need to loop through it using foreach(). Otherwise, just echo it.
 *  Thread Starter [Anastasia Che](https://wordpress.org/support/users/anastasia-che/)
 * (@anastasia-che)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030980)
 * This code outputs “NULL”, despite the fact all values are set.
    Looks like something
   is wrong with selects in plugin.
 *  Plugin Author [Matt Gibbs](https://wordpress.org/support/users/mgibbs189/)
 * (@mgibbs189)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030982)
 * No, there’s nothing wrong with the plugin.
 * The odds are that you’re using that code outside of the Loop. It either need 
   to be inside of the WordPress loop, or you’ll need to manually pass it the current
   post ID using the 2nd parameter.
 *     ```
       CFS()->get( 'step_color', 12345 );
       ```
   
 *  Thread Starter [Anastasia Che](https://wordpress.org/support/users/anastasia-che/)
 * (@anastasia-che)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030983)
 * Thank you!
    Sorry, but it still outputs NULL.
 * Please take a look at my screenshots:
    [https://www.dropbox.com/s/099kjv99j74ksy6/select_error.png?dl=0](https://www.dropbox.com/s/099kjv99j74ksy6/select_error.png?dl=0)
 * Thank you!
 *  Plugin Author [Matt Gibbs](https://wordpress.org/support/users/mgibbs189/)
 * (@mgibbs189)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030984)
 * It looks like “step_color” is within a loop. If so, then outputting it is slightly
   different.
 *     ```
       $steps = CFS()->get( 'step' ); // the loop field is an array of arrays
       foreach ( $steps as $step ) {
           var_dump( $step['step_color'] );
       }
       ```
   
 * Does that help?
 *  Thread Starter [Anastasia Che](https://wordpress.org/support/users/anastasia-che/)
 * (@anastasia-che)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030985)
 * > It looks like “step_color” is within a loop.
 * You are correct, it’s within repeating field.
 * > Does that help?
 * Yeah, it works! It outputs array of data of all steps. 🙂
    `array(1) { ["red"]
   => string(3) "red" } array(1) { ["red"]=> string(3) "red" } array(1) { ["green"]
   => string(5) "green" } array(1) { ["green"]=> string(5) "green" } array(1) { ["
   green"]=> string(5) "green" } array(1) { ["green"]=> string(5) "green" } array(
   1) { ["red"]=> string(3) "red" }` etc.
 * Looks like you should put it into documentation. 🙂
 * Thank you for your help!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Output Select values’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-field-suite.svg)
 * [Custom Field Suite](https://wordpress.org/plugins/custom-field-suite/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-field-suite/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-field-suite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-field-suite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-field-suite/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [Anastasia Che](https://wordpress.org/support/users/anastasia-che/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/output-select-values/#post-6030985)
 * Status: resolved