Can’t figure out what I’m doing incorrectly here
this is at the top of the template file
<?php
/**
* @package 1
* @since 1 1.0
*/
$source_name = get_post_meta($post->ID, 'Source Name', true);
$source_url = get_post_meta($post->ID, 'Source URL', true);
?>
here is the other part thats further down:
<?php if($source_url) { ?>
<div id="content-source">
<span>Source:</span> <a href="<?php echo $source_url; ?>"> <?php echo $source_name; ?></a>
</div>
<?php } ?>
If I remove <?php if($source_url) { ?>
and <?php } ?>
it works fine, but how do I get it to work so if theres no source nothing will be displayed?
A quick look-up of the
get_post_meta()
function:So, try:
Previous you were checking if nothing is returned. You need to be checking for an empty string instead.