<?php
if ( get_post_custom_values("treatment_price") ) :
$values = get_post_custom_values("treatment_price");
echo '<h3><strong>From £' . $values[0]. '</strong></h3>';
else :
echo '';
endif;?>
Thread Starter
Stefan
(@stefan83)
Thanks for the reply, Esmi. I’m afraid it still doesn’t work for some reason. To clarify, I’m using:
<?php
if ( get_post_custom_values("treatment_price") ) :
$values = get_post_custom_values("treatment_price");
echo '<strong>£' . $values[0]. ' per treatment</strong>';
else :
echo '';
endif;?>
If I enter 10 as the value, i get ‘£10 per treatment’, but then if I delete the 10 from the field, I’m left with ‘£ per treatment’.
Any ideas?
try:
<?php
if ( !empty (get_post_custom_values("treatment_price") ) ) :
$values = get_post_custom_values("treatment_price");
echo '<strong>£' . $values[0]. ' per treatment</strong>';
else :
echo '';
endif;?>
Works on arrays too, if that’s what being returned:
http://php.net/manual/en/function.empty.php
$values = get_post_meta($post->ID, 'treatment_price', true);
if ($values){
echo '£ ';
echo $values;
echo ' per treatment ';
}
Thread Starter
Stefan
(@stefan83)
Thanks YouON – works like a charm
wordpressismypuppet – That returned an error: Fatal error: Can’t use function return value in write context in…
Dang… over complicated it. It was a long, late night! Good catch YouON.