update_term_meta() not serializing array? Fixed

 WordPress functions like:

update_post_meta()
update_term_meta()
update_user_meta()

will serialize data automatically before adding to the MySQL, so the the data will be stored as serialized string:

$data = Array
(
    [123] => 1
    [a] => 1
    [456] => 1
);

update_term_meta ($termid,'_your_key', $data);
a:3:{i:123;i:1;s:1:"a";i:1;i:456;i:1;}

If you are using PODS to create metadata, somehow it causes the function not to be serialized correctly, so you have to use the function

$data = maybe_serialized($data) 

then

update_term_meta ($termid,'_your_key', $data);

If you want to get back the data, you have to unserialized the data again.

$data = get_term_meta ($termid,'_your_key');
$data = maybe_unserialize($data);

Leave a comment

Your email address will not be published. Required fields are marked *