Hi All,
We have a variety of fields that we want to show on the front end if they have a value, or the value that have is not a specific value.
I have worked out, looking at the docs how to show the field if there is a value.
$value = get_field( "text_field" );
if( $value ) {
echo $value;
} else {
echo 'empty';
}
And this works great.
But, we have some value options that are like this
Do Not Show, 1, 2, 3, 4, 5
So, how can I alter the code above to only show the field value if the options are 1,2,3,4,5 ?
If the value is “Do Not Show” then dont show the field
Cheers for any help or shoves in the right direction 🙂
You could do something like:
$value = get_field('text_field');
if( $value && $value != 'Do Not Show' ) {
echo $value;
}
Hi wpfieldwork,
I am trying to make this as a shortcode – and it is working, but ignoring the “Do Not Show” and just showing that value anyway – any ideas?
// shortcode for page
function shortcodeinfo() {
$value = get_field( "thefield" );
if( $value && $value != "Do Not show") {
return '&value';
} else {
return '';
}
}
// Register shortcode
add_shortcode('shortcodetoadd', 'shortcodeinfo');
The comparison is case sensitive so is “Do Not show” exactly what the string reads? (with Not capitalized and show not capitalized?)