How to retrieve a value via get_option when the option_value is stored in a multi-dimensional array?

I’m trying to determine how to retrieve custom values from wp_options when the values are stored in a single options array.

For example, I’ve got the following data in wp_options for option_value where option_name = “my_category_fields_option”. The i:n value represents the category id of the category that holds the custom “my_title” data]

Read More

a:2:{i:10;a:1:{s:8:”my_title”;s:48:”Iced Tea: A Great Choice for Cooling Refreshment”;}i:20;a:1:{s:8:”my_title”;s:30:”Black Tea is Good for the Soul”;}}

How would I retrieve the value for “my_title” (which should be “Hello World”) when I’m viewing the category archive page for this category?

Related posts

Leave a Reply

2 comments

  1. If you pass an array to the update_option it will automatically serialize it. you can later retrieve them back into an array like this.

    $tempoptions = get_option("plugin-options");
    if (!empty($tempoptions)) {
        foreach ($tempoptions as $key => $option)
            $options[$key] = $option;
    }
    

    then do something like var_dump ($options) this will show you the entire array.

    I think they use the maybe_serialize/maybe_unserialize/is_serialized functions from the codex, but I never really looked into it. Just found them now.
    http://codex.wordpress.org/Function_Reference/maybe_serialize