0

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 :)

3
  • I did do it. I'm still confused by the system and the ratings here so do forgive me.
    – jimilesku
    Jul 20, 2011 at 13:11
  • what is retrieve_cat_data can we see that function?
    – Bainternet
    Jul 20, 2011 at 13:12
  • there is no function it refers to the dropdown menu form
    – jimilesku
    Jul 20, 2011 at 13:14

1 Answer 1

1

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'); ?>
3
  • 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, 2011 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, 2011 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, 2011 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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