Wordpress序列化数据2次,同时尝试使用add_post_meta函数添加post meta

时间:2017-07-13 08:53:13

标签: php wordpress serialization

我有使用add_post_meta序列化数据wordpress的问题

这是使用调试打印序列化数据的正确结果

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";}}}}

这是序列化存储在postmeta表中的wordpress数据的错误结果

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序列化数据2次?

抱歉英文不好

由于

1 个答案:

答案 0 :(得分:0)

简而言之,wordpress将数据序列化2次

这是php代码

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

这是一个正确的序列化结果

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

这是一个存储在postmeta表中的wordpress序列化结果

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

由于