0

I'm trying to unserialize data from WP's MySQL table. It looks like this enter image description here

my function from template-page.php

<?php
function get_values(){
        global $wpdb;
        $parsed = $wpdb->get_results("SELECT option_value FROM wp_options WHERE option_id = 375", ARRAY_N);
        $result = var_export($parsed[0][0], true);
        echo $result;
}
get_values();
?>

the output on my page is a very long string of serialized data: enter image description here

I've tried unserialize($result); and then print it out on my page but it's not working. gettype() shows that it's FALSE, which probably means something wrong with serialized data? But as I'm new to WP/php I think it's probably my fault somewhere.

What I need to do is simply get the data from MySQL -> transform it to php object -> change some variables -> and push it back to MySQL table. Where I missed something? thanks!

  • Any particular reason you’re not just using get_option()? – Jacob Peattie Oct 10 '18 at 10:28
1

As @Jacob said :

To retrieve your option data :

$your_data = get_option('option_tree');

To save your new data to the option :

$new_data = array(...);
update_option('option_tree', $new_data);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.