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]

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?

2 Answers 2

$term_id = get_query_var('cat'); // the current category ID

$my_fields = get_option('my_category_fields_option');
echo $my_fields[$term_id]['my_title']; // the title corresponding to the current category

(assuming you're talking about Any examples of adding custom fields to the category editor?)


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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