Last active
December 26, 2015 22:29
-
-
Save voodooGQ/7223008 to your computer and use it in GitHub Desktop.
Post Meta Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns all "public" meta items for $post in the form of an object | |
* Useful for reducing server calls | |
* | |
* @param int $post_id The ID of the post | |
* @return object | |
*/ | |
function post_meta_object($post_id) { | |
$meta = get_post_meta($post_id); | |
$object = new stdClass(); | |
foreach($meta as $key => $value) { | |
if(substr($key, 0, 1) === "_") { | |
continue; | |
} | |
if(is_array($value)) { | |
$value = $value[0]; | |
} | |
$object->$key = $value; | |
} | |
return $object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment