Support » Fixing WordPress » [Code Related] Checkbox to Dropdown Conversion?

  • soulgeek

    (@soulgeek)


    Folks,

    I have a Checkbox codes for Categories:

    <?php 
    
      $categories = get_categories( 'orderby=name&hierarchical=0&hide_empty=0' );
    
      $n = 1;
    
      foreach ( $categories as $cat ): ?>
    
      <input type="checkbox" name="postcats[]" value="<?php echo $cat->cat_ID; ?>" >
    
        <?php 
    
    	echo $cat->cat_name; 
    
      $n = $n +1;
    endforeach; ?><input type="hidden" name="abb_num_cats" value="<?php echo $n;?>">

    Observe, the Checked categories are stored in $postcats[].

    The Dropdown equivalent of Checkbox code is:

    <select name="postcats">
    	<?php
    	$categories = get_categories( 'orderby=name&hierarchical=0&hide_empty=0' );
      	$n = 1;
        foreach ( $categories as $cat ):
    	$cat_id = $cat->cat_ID;
    
    	?>
    
    	<option name="postcats[]" value="<?php echo $cat_id;?>" <?php if ($cat_id==$amaniche_main_category){echo "selected";}?>>
    
    	<?php
    	echo $cat->cat_name;
    	?>
    	</option>
    	<?php
        $n = $n +1;
        endforeach; ?>
    
    </select>

    My Question is: In the Dropdown codes, how to Store selected option values in Array $postcats[].

    I will be so so so Grateful to you, if someone can help me out.

  • The topic ‘[Code Related] Checkbox to Dropdown Conversion?’ is closed to new replies.