update_term_meta() not serializing array? Fixed

 WordPress functions like:


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);

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) 


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 Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>