Question

I'm using this code to show my field:

<?php echo '@ ' . get_post_meta(get_the_ID(), 'Author:', true); ?>

When I add a field in my posts it shows it with no problem but for posts that I don't add any fields it shows "@". What I can do to not show anything if field is empty in a post? Examples: field with data - field with no data [Warning: Both links are NSFW +18]

Was it helpful?

Solution

You can just make a simple check, to see if you have this meta

$author = get_post_meta(get_the_ID(), 'Author:', true);

if ( $author ) :
    echo '@ ' . $author;
endif;
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top