我刚刚开始在wp\\U选项中以多维数组存储数据,我需要一些帮助来检索一些数据。。。
我的数据位于下面,存储为option\\u name“My\\u category\\u fields”
我需要提取一个类别ID字符串,其中my\\u cat\\u hide设置为true。我把我的职能放在这里了。我如何完成它?
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;
}
my\\u category\\u字段:
a:17:{
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:7;a:1:{s:13:"my_cat_title";s:0:"";}
i:19;a:1:{s:13:"my_cat_title";s:0:"";}
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:37;a:1:{s:13:"my_cat_title";s:0:"";}
i:16;a:1:{s:13:"my_cat_title";s:0:"";}
i:5;a:2:{s:13:"my_cat_title";s:0:"";s:12:"my_cat_hide";N;}
i:6;a:1:{s:13:"my_cat_title";s:0:"";}
i:8;a:1:{s:13:"my_cat_title";s:0:"";}
i:3;a:1:{s:13:"my_cat_title";s:0:"";}
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";}
i:38;a:2:{s:13:"my_cat_title";s:0:"";s:12:"my_cat_hide";s:4:"true";}
i:39;a:2:{s:13:"my_cat_title";s:0:"";s:12:"my_cat_hide";s:4:"true";}
i:40;a:2:{s:13:"my_cat_title";s:0:"";s:12:"my_cat_hide";s:4:"true";}
}
最合适的回答,由SO网友:sorich87 整理而成
应采用以下方法:
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;
}