Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted
$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?)

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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