WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm just starting to store data in multi-dimensional arrays in wp_options and I need some help to retrieve some data...

My data is below and is stored as option_name "my_category_fields"

I need to pull a string of category ids in which the my_cat_hide is set to true. I've stubbed my function here. How do I complete it?

function get_hidden_cats()
$my_cats = get_option('ce4_category_fields');
    //how do I capture the list of category ids where my_cat_hide is 'true'?
    $my_hidden_cats = ?
    return $my_hidden_cats;


    i:20;a:1:{s:13:"my_cat_title";s:30:"Black Tea is Good for the Soul";}
    i:9;a:1:{s:13:"my_cat_title";s:58:"Herbal Chinese Tea is a spectacular blend of herbs and tea";}
    i:44;a:1:{s:13:"my_cat_title";s:24:"This is my 9th category!";}
    i:4;a:2:{s:13:"my_cat_title";s:28:"My test Title for Chai Tea 4";s:12:"my_cat_hide";N;}
    i:10;a:1:{s:13:"my_cat_title";s:59:"Iced Tea: The Great Southern Choice for Cooling Refreshment";}
    i:36;a:1:{s:13:"my_cat_title";s:28:"Full title for this category";}
share|improve this question
isn't ce4_category_fields a array? use implode if you want it as a string... – onetrickpony Jan 23 '11 at 7:35
Your code should not look like the second block you've posted above after you've called get_option, because it should be unserializing that data when called(that's how it would typically appear in the DB). – t31os Jan 23 '11 at 10:28
up vote 2 down vote accepted

The following should do it:

function get_hidden_cats() {
    $my_cats = get_option('ce4_category_fields');

    $my_hidden_cats = array();
    foreach( $my_cats as $cat_id => $cat_attrs ) {
        if( 'true' == $cat_attrs['my_cat_hide'] )
            $my_hidden_cats[] = $cat_id;
    $my_hidden_cats = implode( ',', $my_hidden_cats );

    return $my_hidden_cats;
share|improve this answer
Sweet. Thanks as always sorich :) – Scott B Jan 24 '11 at 4:10
You are welcome. ;) – sorich87 Jan 24 '11 at 7:12

Your Answer


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.