Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;
}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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?

share|improve this answer
    
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 '11 at 15:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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