I have this function and I need to somehow exclude a category number 14 from my submission form. Is there any way to do it inside this function?
function retrieve_cat_data($byid = false){
$massive_categories_obj = get_categories('hide_empty=0');
if($byid):
$massive_categories = array();
foreach ($massive_categories_obj as $massive_cat) {
if($massive_cat->cat_ID != 1) $massive_categories[$massive_cat->cat_ID] = $massive_cat->cat_ID;
}
$categories_tmp = array_unshift($massive_categories, "0" );
else:
$massive_categories = array();
foreach ($massive_categories_obj as $massive_cat) {
if($massive_cat->cat_ID != 1) $massive_categories[$massive_cat->cat_ID] = $massive_cat->cat_name;
}
$categories_tmp = array_unshift($massive_categories, __('Select a category:', 'bo') );
endif;
return $massive_categories;
}
function retrieve_cat_data_sp( $exclude ){
$args = array(
'hide_empty' => '0',
'exclude' => $exclude
);
$massive_categories_obj = get_categories($args);
$massive_categories = array();
foreach ($massive_categories_obj as $massive_cat) {
if($massive_cat->cat_ID != 1) $massive_categories[$massive_cat->cat_ID] = $massive_cat->cat_ID;
}
$categories_tmp = array_unshift($massive_categories, "0" );
return $massive_categories;
}
What about using the
exclude
array key in yourget_categories()
call?e.g. change this:
to this:
Note that
exclude
expects a comma-separated string as a value.For your second function, what are you passing as
$exclude
?Are you passing a comma-separated string, an array, or something else?
What do you get from this
get_categories( $args )
call? Try avar_dump( $massive_categories_obj )
to see what it’s returning?