This snippet is a perfect case of a developer not considering what plugins might be doing with post meta. The snippet grabs all of the post meta attached to the current post and displays it, all of it. The only time meta isn’t displayed is if the meta key starts with an underscore (_), which means it is a hidden field, or if the key is “enclosure”.
While a lot of the time this is perfectly acceptable, and won’t result in any strange info being displayed, but what about plugins that add post meta and do not prefix it with _? While it may be a best practice to prefix meta field IDs with an underscore, it’s very common not to do so (and perfectly acceptable), and if a plugin does it not prefix the meta fields is running, all of their fields will be displayed.
<?php $meta_keys = get_post_meta( get_the_ID() ); ?> <?php foreach( $meta_keys as $meta => $value ) : ?> <?php if( ( '_' != $meta ) && ( 'enclosure' != $meta ) ) : ?> <span class="custom-meta"><strong><?php echo $meta; ?>:</strong> <?php echo $value; ?></span> <?php endif; ?> <?php endforeach; ?>
When doing this type of thing, please keep in mind what plugins may be doing so that you don’t create a lot of unexpected display issues for users and other developers.
Submitted by Chris Klosowski.