Skip to content

Instantly share code, notes, and snippets.

@sibysathyanesan
Created June 7, 2019 11:32
Show Gist options
  • Save sibysathyanesan/f3f46d34bcac956e156c57d0ce5a331d to your computer and use it in GitHub Desktop.
Save sibysathyanesan/f3f46d34bcac956e156c57d0ce5a331d to your computer and use it in GitHub Desktop.
wordpress category dropdown
<div class="class-drop">
<select name="batch_sel" >
<option value="all" <?php if($_GET['batch_sel'] == 'all'){echo 'selected'; } ?> >All </option>
<?php
$terms = get_terms( array(
'taxonomy' => 'result-year',
'hide_empty' => false, ) );
$batch_slugs = wp_list_pluck( $terms, 'slug' );
foreach($terms as $term):
?>
<option value="<?= $term->slug ?>" <?php if($term->slug == $_GET['batch_sel']) { echo 'selected';} ?>> <?= $term->name ?> </option>
<?php endforeach ?>
</select>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment