admin管理员组文章数量:1321052
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 badges1 Answer
Reset to default 1You 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;
本文标签: phpHide wordpress field if data is empty in post
版权声明:本文标题:php - Hide wordpress field if data is empty in post! 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742094111a2420440.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论