I have a custom WordPress panel for my posts which I am referencing with this
$service = get_post_meta($post->ID, 'service', true);
I’m trying to insert some HTML that says:
if ($service == 1) {
echo "Water Damage";
}
if ($service == 2) {
echo "Fire Damage";
}
and so on. This part is not working. If I simply print the results of $service, that will display the appropriate numerical value, but I can’t get the above to work.
If i’m right on this, the problem is that you are addressing
$serviceas an int.Have a look in the codex (http://codex.wordpress.org/Function_Reference/get_post_meta) , and you’ll see that if the third Parameter is false it’ll return an array of values, and if it’s true (like in you case) it’ll returns a string.
In the example above you where trying to compare a string to an int. try to do this instead: