Advertisement
miriamdepaula

WordPress: Custom post type filter

Sep 23rd, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. // Adds a new custom filter for a custom post type
  3.  
  4. function imovel_imoveis_category_filters() {
  5.     global $typenow;
  6.  
  7.     // an array of all the taxonomyies you want to display. Use the taxonomy name or slug
  8.     $taxonomies = array('imoveis_category');
  9.  
  10.     // must set this to the post type you want the filter(s) displayed on
  11.     if( $typenow == 'imovel' ){
  12.  
  13.         foreach ($taxonomies as $tax_slug) {
  14.             $tax_obj = get_taxonomy($tax_slug);
  15.             $tax_name = $tax_obj->labels->name;
  16.             $terms = get_terms($tax_slug);
  17.             if(count($terms) > 0) {
  18.                 echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
  19.                 echo "<option value=''>Todos os tipos</option>";
  20.                 foreach ($terms as $term) {
  21.                     echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
  22.                 }
  23.                 echo "</select>";
  24.             }
  25.         }
  26.     }
  27. }
  28. add_action( 'restrict_manage_posts', 'imovel_imoveis_category_filters' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement