最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Hide wordpress field if data is empty in post!

programmeradmin2浏览0评论

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]

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]

Share Improve this question asked Sep 29, 2020 at 12:37 ElenorGomezElenorGomez 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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;
发布评论

评论列表(0)

  1. 暂无评论