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;
}
}
?>
No, it doesn’t help, sorry. π
In this case nothing outputs. But I have non-empty values there which I need to output. π
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!
$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.
This code outputs “NULL”, despite the fact all values are set.
Looks like something is wrong with selects in plugin.
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 );
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
Thank you!
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?
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!