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 need a bit of quick help. How do I exclude category ID number 50 for example in drop down list form in Wordpress?

I have this code and I need to just insert the excluded category id.

<?php
$cate_id = retrieve_cat_data(true);
$cate_name = retrieve_cat_data(false);
for ($i = 0; $i < count($cate_name); $i++ ) { 
?>

<option value="<?php echo $cate_id[$i]; ?>"><?php echo $cate_name[$i]; ?>
</option><?php } ?>

Thanks in advance to everyone :)

share|improve this question
    
20% accept rate!!! please go back to your old question and accept some answers, its the least you can do to thank the good people of the community who take their time to answer you questions. –  Bainternet Jul 20 '11 at 12:44
    
I did do it. I'm still confused by the system and the ratings here so do forgive me. –  jimilesku Jul 20 '11 at 13:11
    
what is retrieve_cat_data can we see that function? –  Bainternet Jul 20 '11 at 13:12
    
there is no function it refers to the dropdown menu form –  jimilesku Jul 20 '11 at 13:14
add comment

1 Answer

up vote 1 down vote accepted

try:

<?php
$cat_to_EXCLUDE = 50;
$cate_id = retrieve_cat_data(true);
$cate_name = retrieve_cat_data(false);
for ($i = 0; $i < count($cate_name); $i++ ) { 
?>
if ($cate_id[$i] != $cat_to_EXCLUDE){
<option value="<?php echo $cate_id[$i]; ?>"><?php echo $cate_name[$i]; ?>
</option><?php }} ?>

update:

if you search your theme's functions.php file i bet you will find a function named retrieve_cat_data

anyway you can simple create a dropdown using wp_dropdown_categories and you can exclude a category with its exclude argument :

<?php wp_dropdown_categories('exclude=50'); ?>
share|improve this answer
    
UPDATE: This works great but there is an issue that appears. The form value takes the first category and makes it default in the drop down menu. But that can create problems because a user can forget to choose a proper category. Is there a way to leave the first option blank so the user is forced to choose between available categories? –  jimilesku Jul 20 '11 at 14:59
    
Hey I've found it : if you search your theme's functions.php file i bet you will find a function named retrieve_cat_data. Here is the PASTIE CODE: pastie.org/2243250 HELP :D: –  jimilesku Jul 20 '11 at 15:08
    
I've also tried this and it works: <option value="<option value="<?php wp_dropdown_categories('exclude=34, selected=0'); ?> </option> but now I need a dummy text to replace the empty form value to : choose your category! Can this be done? –  jimilesku Jul 20 '11 at 15:30
add comment

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.