Grymfogel1 Grymfogel1 - 1 year ago 80
PHP Question

Sorting out array of postmeta in database

I need to sort out different components of a metadata string in the table postmeta in my WordPress database.

The string looks like this in the database:

a:1:{i:0;a:4:{s:8:"employer";s:15:"ExampleEmployer";s:9:"job_title";s:9:"Job Title";s:4:"date";s:9:"2014-2016";s:5:"notes";s:20:"Experience(job)notes";}}

I got quite worried when I saw this the first time, and tried to search for a more humane row, but couldn't find one, so this is the only one with the information I need.

The information is from a plugin call WP Job Manager, and I haven't found any documentation on how to sort their array out, so I'm asking you kind people.

Thank you!

EDIT: I'm very tired. The string automatically unserializes when fetched from the database, I just saw that now. Thank you all for your help.

Answer Source

It is a serialized String. You have to unserialize the string and fetch the output.

$serialized_data = serialize(array('Math', 'Language', 'Science'));  
echo  $serialized_data . '<br>';  
// Unserialize the data  
$var1 = unserialize($serialized_data);  
// Show the unserialized data;  
var_dump ($var1);  





array(3) { [0]=> string(4) "Math" [1]=> string(8) "Language" [2]=> string(7) "Science" } 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download