I am trying to make it so that when a particular field's value is filled with a specific option, it echos out a specific bit of code. My code is:
<?php
$score = types_render_field('overall-score',array('raw'=>true));
if ( $score == 'Positive') {
echo '<div class="score-positive"><i class="fas fa-plus-circle">Asses</div>';
}
else {
echo 'Failed';
}
?>
I'm not sure what I've got wrong here.
Hello, sorry there seems to have been a problem with the chat system. One thing to remember here is that types_render_field may produce extra markup, depending on the type of field. If you want the raw value from the database, you can use get_post_meta instead. In this syntax, you must also use the wpcf- prefix for the field, like this:
$post_id = 12345;
$score = get_post_meta( $post_id, 'wpcf-overall-score', true);
if ( $score == 'Positive') {
echo '<div class="score-positive"><i class="fas fa-plus-circle">Asses</div>';
}
else {
echo 'Failed';
}
Hey Christian,
Thanks for the response. Unfortunately it's still just returning the else. I did try modifying it slightly since I'm not sure how to use the post_id here properly:
<?php
$score = get_post_meta( $post->ID, 'wpcf-overall-score', true);
if ( $score == 'positive') {
echo '<div class="score-positive"><i class="fas fa-plus-circle">Sum</div>';
}
else {
echo 'Failed';
}
?>
But even unmodified it still posted as "Failed". Any ideas?
My issue is resolved now. Thank you!