[英]Displaying those Custom Meta Field with Value only in Wordpress
I have a Wordpress custom Meta Field and I want to display only those fields that have a value in it ( and not display those where the user has not put a value). 我有一个Wordpress自定义元字段,我只想显示其中具有值的那些字段(而不显示那些用户未输入值的字段)。
How I can go about doing this? 我该怎么做呢?
Just wrap your code to display in if condition: 只需包装您的代码以在以下情况下显示:
<?php if (get_post_meta(get_the_ID(), "field_name", true)): ?>
<!-- here your html & meta echo or-->
<?php echo get_post_meta(get_the_ID(), "field_name", true) ?>
<?php endif; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.