Opened 14 years ago
Closed 14 years ago
#13463 closed defect (bug) (duplicate)
post_meta doesn't like objects
Reported by: | tychay | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0 |
Component: | Posts, Post Types | Keywords: | add_post_meta, get_post_meta |
Focuses: | Cc: |
Description
make an object with data like this
$data = (object) array('primary'=>'blah','data'=>array(1,38243,238,'foo'));
add_post_meta($post_id, 'testmeta', $data);
get_post_meta($post_id, 'testmeta');
You get errors of the sort…
[20-May-2010 16:50:14] PHP Catchable fatal error: Object of class stdClass could not be converted to string in /home/wpdev/public_html/wp-includes/formatting.php on line 1229
[20-May-2010 16:50:14] PHP Stack trace:
…
[20-May-2010 16:50:14] PHP 4. add_post_meta()
[20-May-2010 16:50:14] PHP 5. add_metadata() /home/wpdev/public_html/wp-includes/post.php:1157
[20-May-2010 16:50:14] PHP 6. stripslashes_deep() /home/wpdev/public_html/wp-includes/meta.php:54
[20-May-2010 16:50:14] PHP 7. stripslashes() /home/wpdev/public_html/wp-includes/formatting.php:1229
when deserializing, you get nothing. If you deserialize an array of objects, you'll get an array back where the first value is the serialize with all objects replaced with "Object" and subsequent values containing serialized strings of the rest of the content.
(Note: I put this in Post Types because I don't know what component meta is attached to. Please reassign bug if wrong.)
Duplicate of #12860