Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Database serialized array issue

Got an issue when inserting a blank serialized array into the database. I'm using wordpress (just for full disclosure, shouldn't make a difference) and using the add_post_meta() function to input some additional information. Here's a snippet:

add_post_meta($post_id, 'information', serialize(array()));

The serialized array is intentionally blank for the moment. Anyway here's the expected/actuals:

// Expected value 
a:0:{}

// Actual value
s:6:"a:0:{}";

Any help?

like image 682
ScottMcGready Avatar asked Nov 30 '25 21:11

ScottMcGready


1 Answers

Add post meta auto-serializes arrays. And also get post meta, pass TRUE at the last argument: like get_post_meta($post_id, 'information', TRUE);

More details here: http://codex.wordpress.org/Function_Reference/add_post_meta

like image 123
Eek Avatar answered Dec 02 '25 11:12

Eek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!