The documentation from get_post_meta
makes it sound as if the single
argument will determine whether or not meta values are returned in an array or not. For example:
// If I set single to false, or leave it blank it's returned as an array
[my-meta] => Array
(
[0] => my-value
)
// If I set single to true, it's returned as a string
[my-meta] = my-value
This works fine if I'm only returning data for a single meta key...but fails if I want to return all of the meta data, but return them all as strings (single).
It would seem that the proper call to get all of the meta values with string values would be:
$meta = get_post_meta( $transaction->ID, false, true );
But this returns with the array values and completely ignores the single
value.
Why? Is there a way to get all of the meta data, but without the single element arrays? Those are unnecessary in my case.
EDIT: Just to clarify what I'm asking, I'd lie to get all of the meta like this:
array() {
[my-meta-1] = my-value
[my-meta-2] = my-value
[my-meta-3] = my-value
[my-meta-4] = my-value
}
Rather than like this (which is the only behavior I seem to be able to get):
array() {
[my-meta-1] => Array
(
[0] => my-value
)
[my-meta-2] => Array
(
[0] => my-value
)
[my-meta-3] => Array
(
[0] => my-value
)
[my-meta-4] => Array
(
[0] => my-value
)
}
get_post_meta()
is doing correctly by returning an array if no meta key is specified. Also, that behaviour is specified in the Codex (quoting codex): "If $single is set to true, the function returns the first value of the specified key (not in an array)"