我希望抓取给定帖子的所有自定义帖子元字段,并将它们显示在页面上,这是我用以下代码完成的。
但是,我想检查(!empty())是否为自定义post元数据,并且不打印任何为空的值。
除此之外,这应该是非常直接的,但我会感谢你的帮助。
<?php
$custom_fields = get_post_custom();
foreach ( $custom_fields as $field_key => $field_values ) {
if(!isset($field_values[0])) continue;
if(in_array($field_key,array("hits","_wp_trash_meta_time","SKU","sub-category-2","sub-category-1","_wp_trash_meta_status","old_price","price","qty","additional_notes","buy_link","customlist1","customlist2","featured","image","images","_edit_lock","_edit_last","_thumbnail_id","_sexybookmarks_permaHash","_sexybookmarks_shortUrl"))) continue;
foreach ( $field_values as $key => $value )
echo \'<li><strong>\' . $field_key . \':</strong> \' . $value . \'</li>\';
}
?>