1

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

1 Answer 1

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?

1
  • it worked. It is a submit form, when chosen the category it displays the upload and submit button, if not, those are hidden.
    – jimilesku
    Oct 24, 2011 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.