php - Get selected value from dropdown menu, from an array? -


i feel missing here. did manual customizations on short (wordpress) script , try set <select><option> "selected" if has been selected. in order accomplish this, tried find out if $term->id = similar selected option value (which id well). far, cannot seem submitted <select><option>. says 'array'.

below script. see doing wrong here? clear, seems $_get["listing_cat"] here. when try print $_get["listing_cat"] within foreach outputs 'array'.

<form method="get" action="<?php echo trailingslashit( home_url() ); ?>" class="custsearch"> <select name="listing_cat[]"> <option value="1" disabled="disabled" <?php if(!count($_get)>0 || !$_get["listing_cat"] ){ echo 'selected="selected"';} ?>>pls choose</option>         <?php         $cat_args = array(         'orderby'           => 'id',          'parent'        => 0,         'hide_empty'    => false                );         $terms = get_terms('listing_category', $cat_args );         foreach ($terms $term) {             printf( '<option class="level-0" value="' . $term->term_id .'"');             if($_get["listing_cat"] == $term->term_id) { echo 'selected="selected"'; }             printf( '>%s</option>', $term->slug, $term->name );         }          ?> </select> </form> 

ok here needed.. quite logical;). put function , needed in_array() check:

//category in dropdown function the_refine_category_ui2() {     $cat_args = array(     'orderby'           => 'id',      'parent'        => 0,     'hide_empty'    => false            );     $terms = get_terms('listing_category', $cat_args );  foreach ($terms $term) {     printf( '<option class="level-0"');    if( in_array( $term->term_id, $_get["listing_cat"] )) { echo 'selected ';}       printf('value="' . $term->term_id .'"');             printf( '>%s' . $term->term_id .'</option>', $term->slug, $term->name );   } } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -