Created
April 8, 2019 06:21
-
-
Save adamcrampton/f5c933409c0ec09a513d24ef5cf279e4 to your computer and use it in GitHub Desktop.
WordPress - Return all post meta values in flat array
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 | |
// Return all meta for a single post in a flat array. | |
function get_all_post_meta($post_id) { | |
// Get all the meta values. | |
$meta = get_post_meta($post_id, ''); | |
// We only need the first item - return a flat array. | |
return array_map(function($item) { | |
return $item[0]; | |
}, $meta); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added the code to remove service fields, like "_edit_lock":
`<?php
function get_all_post_meta($post_id) {
// Get all the meta values.
$meta = get_post_meta($post_id, '');
}
`