Opened 13 years ago
Last modified 6 years ago
#20853 assigned defect (bug)
get_post_custom show directly serialized data from the post_meta arrays.
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 1.5 |
Component: | Options, Meta APIs | Keywords: | dev-feedback |
Focuses: | Cc: |
Description
get_post_custom show directly serialized data from the post_meta arrays.
For example:
If I save a data with:
update_post_meta( $post_id, 'camp', array( 'some' => $var, 'thing' => $var_2 ) );
When I use get_post_meta(); :
$var_get = get_post_meta($post_id, 'camp', true); echo $var_get['some']; // Fine.. Print: $var content.
but, when I use get_post_custom() :
$var = get_post_custom($post_id); echo $var['some']; Metod, (Not work because "Returns a multidimensional array" with all values, and 0 is the first or the unique value). echo $var['some'][0]; /* Metod, >:( , Not work. Print: a:2:{i:some;s:4:"this";i:thing;s:7:"content";} */
Instead of display "array", and can not handle sub arrays.
Change History (12)
#4
@
13 years ago
The Codex page for get_post_custom
states:
Note: not only does the function return a multi-dimensional array (ie: always be prepared to deal with an array of arrays, even if expecting array of single values), but it also returns serialized values of any arrays stored as meta values. If you expect that possibly an array may be stored as a metavalue, then be prepared to 'maybe_unserialize'.
#5
@
13 years ago
- Keywords 2nd-opinion added; needs-patch removed
- Version changed from 3.4 to 1.5
Yes, that's how it always worked, but I'm not really sure why.
#6
@
13 years ago
So, would be good to add an option to this function to deserialize the serialized data?
Example:
get_post_custom($post_id, true);
:/
#7
@
13 years ago
It's not that easy. get_post_custom() is just an alias for get_post_meta(), which is an alias for get_metadata().
#8
@
13 years ago
I mean sure, you could add the deserialization logic directly into get_post_custom() but that would create a big inconsistency.
#10
@
12 years ago
- Cc paul@… added
I came across this issue yesterday and was about to open a ticket for it, but then found the documentation in the Codex (and this ticket).
While it is documented, I agree with the original poster that it is a bug. Note that it also applies to get_post_custom_values()
and it is not documented there (at least directly, altho there is a reference to the Codex entry for get_post_custom()
).
Edit: