Only 'echo' if custom fields exist
-
I’m having trouble creating 2 custom fields. I tried looking at get_post_custom() but I got in way over my head, because it was breaking the code somehow.
What I need is to add a Publication date and the publication name (like a magazine for instance) so it looks like this:
Published: 03/12/2010 in Suchandsuch Magazine
The code I have currently works, but it shows the “Published:” and “in” text even if there’s no custom field added, so I need to figure out how to hide that text if there is no custom fields added.
Here’s my current code.
Functions.php file:
function get_custom_field_value($szKey, $bPrint = false) { global $post; $szValue = get_post_meta($post->ID, $szKey, true); if ( $bPrint == false ) return $szValue; else echo $szValue; }
In the loop:
<?php if ( function_exists('get_custom_field_value') ){ echo 'Original Publication: '; get_custom_field_value('publication_date', true); } ?> <?php if ( function_exists('get_custom_field_value') ){ echo 'in '; get_custom_field_value('publication', true); } ?>
Does anyone know how to hide the echo text if there’s no custom fields there?
Thanks!~
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Only 'echo' if custom fields exist’ is closed to new replies.