Skip to content

Instantly share code, notes, and snippets.

@cassler
Created February 7, 2014 03:56
Show Gist options
  • Save cassler/8857177 to your computer and use it in GitHub Desktop.
Save cassler/8857177 to your computer and use it in GitHub Desktop.
wp-get-meta-keys
/**
* Get all meta keys for given object.
*
* Finds all custom meta keys for a given post and extracts them to an array for easy access.
* @example $meta = den_get_meta;
* @example echo ($meta['my-key'] ? $meta['my-key'] : null );
* @return array of meta keys for post
* @author Darin Cassler
* @package den_framework
* @subpackage den_custom_hooks
**/
function den_get_meta() {
global $post;
$meta = array();
$custom_field_keys = get_post_custom_keys($post->ID);
foreach ( $custom_field_keys as $key => $value ) {
$valuet = trim($value);
if ( '_' == $valuet{0} )
continue;
$meta_values = get_post_meta($post->ID,$value);
$meta[$value] = join(', ',$meta_values);
}
return $meta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment