exclude category from WordPress Form function

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;
}

Related posts

Leave a Reply

1 comment

  1. What about using the exclude array key in your get_categories() call?

    e.g. change this:

    $massive_categories_obj = get_categories('hide_empty=0');
    

    to this:

    $massive_categories_obj = get_categories('hide_empty=0&exclude=14');
    

    Note that exclude expects a comma-separated string as a value.

    For your second function, what are you passing as $exclude?

    function retrieve_cat_data_sp( $exclude ){
        $args = array(
            'hide_empty' => '0',
            'exclude' => $exclude
        );
        $massive_categories_obj = get_categories($args);
    

    Are you passing a comma-separated string, an array, or something else?

    What do you get from this get_categories( $args ) call? Try a var_dump( $massive_categories_obj ) to see what it’s returning?