简体   繁体   中英

Wordpress serialize data 2 times while try to add post meta with add_post_meta function

i have problem with serialize data wordpress with add_post_meta

This is correct result of serialize data with debug print

a:1:{s:17:"set_5964c34de5a14";a:8:{s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:2:{s:10:"applies_to";s:5:"roles";s:5:"roles";a:1:{i:0;s:7:"privato";}}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:10:"continuous";s:9:"date_from";s:0:"";s:7:"date_to";s:0:"";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:21:"{temp_quantita_da[1]}";s:2:"to";s:20:"{temp_quantita_a[1]}";s:4:"type";s:11:"fixed_price";s:6:"amount";s:20:"{temp_prezzo_pri[1]}";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:0:"";s:6:"adjust";s:0:"";s:4:"type";s:16:"fixed_adjustment";s:6:"amount";s:0:"";s:9:"repeating";s:2:"no";}}}}

this is wrong result of serialize data of wordpress stored in postmeta table

s:661:"a:1:{s:17:"set_5964c34de5a14";a:8:{s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:2:{s:10:"applies_to";s:5:"roles";s:5:"roles";a:1:{i:0;s:7:"privato";}}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:10:"continuous";s:9:"date_from";s:0:"";s:7:"date_to";s:0:"";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:21:"{temp_quantita_da[1]}";s:2:"to";s:20:"{temp_quantita_a[1]}";s:4:"type";s:11:"fixed_price";s:6:"amount";s:20:"{temp_prezzo_pri[1]}";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:0:"";s:6:"adjust";s:0:"";s:4:"type";s:16:"fixed_adjustment";s:6:"amount";s:0:"";s:9:"repeating";s:2:"no";}}}}";

Wordpress serialized data 2 times?

Sorry for the bad English

Thanks

In short, wordpress serializes the data 2 times

This is php code

$m_value = serialize(array('data test 1','data test 2'));
add_post_meta(4015, '_test_meta', $m_value,TRUE);

this is a correct serialize result

a:2:{i:0;s:11:"data test 1";i:1;s:11:"data test 2";}

This is a wordpress serialize result stored in postmeta table

s:52:"a:2:{i:0;s:11:"data test 1";i:1;s:11:"data test 2";}";

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM