Skip to content

Instantly share code, notes, and snippets.

@rfvcorreia
Created November 15, 2013 12:19
Show Gist options
  • Select an option

  • Save rfvcorreia/7483484 to your computer and use it in GitHub Desktop.

Select an option

Save rfvcorreia/7483484 to your computer and use it in GitHub Desktop.
Add Taxonomy Filter For Custom Post Type
<?php
function salas_add_taxonomy_filters() {
global $typenow;
// an array of all the taxonomyies you want to display. Use the taxonomy name or slug
$taxonomies = array('salas');
// must set this to the post type you want the filter(s) displayed on
if( $typenow == 'evento' || $typenow == 'noticia' || $typenow == 'ementa' || $typenow == 'lembrete' || $typenow == 'aluno' || $typenow == 'paginas_privadas'){
foreach ($taxonomies as $tax_slug) {
$tax_obj = get_taxonomy($tax_slug);
$tax_name = $tax_obj->labels->name;
$terms = get_terms($tax_slug);
if(count($terms) > 0) {
echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
echo "<option value=''>Mostrar Todas as $tax_name</option>";
foreach ($terms as $term) {
echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' </option>';
}
echo "</select>";
}
}
}
}
add_action( 'restrict_manage_posts', 'salas_add_taxonomy_filters' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment