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

metabox - Check if any meta on the post has value then display content

programmeradmin2浏览0评论

I know how to use the conventional get_post_meta, and I usually call it with each field separately. Is there a way to use them all at once? For example, use an if statement to display content if any metabox field has content. Not specific to one, but any in the post.

I tried searching for this with no success

So far this works but what if we have a lot of more metaboxes, no easy check on all to find value?

<?php $meta1 = get_post_meta( $post->ID, 'metabox_1', true );
$meta2 = get_post_meta( $post->ID, 'metabox_2', true );
if (!empty($meta1) || !empty($meta2)){?>
//do stuff
<?php } ?>
发布评论

评论列表(0)

  1. 暂无评论