我需要使用现有类别的数组作为下拉选项值,然后使用所选类别ID。更确切地说,我尝试使用Visual Composer插件创建一个自定义模块来显示所选类别的最新帖子tutorial.
我试着用wp_dropdown_categories
在下面的代码中,我发现了一些错误,但什么都不起作用:
array(
\'param_name\' => \'category_id\',
\'type\' => \'dropdown\',
\'value\' => wp_dropdown_categories, // here I\'m stuck
\'heading\' => __(\'Category filter:\', \'overmax\'),
\'description\' => \'\',
\'holder\' => \'div\',
\'class\' => \'\'
),
谢谢
最合适的回答,由SO网友:Rajeev Vyas 整理而成
Try this,
$categories_array = array();
$categories = get_categories();
foreach( $categories as $category ){
$categories_array[] = $category->term_id;
}
array(
\'param_name\' => \'category_id\',
\'type\' => \'dropdown\',
\'value\' => $categories_array, // here I\'m stuck
\'heading\' => __(\'Category filter:\', \'overmax\'),
\'description\' => \'\',
\'holder\' => \'div\',
\'class\' => \'\'
),