Created
September 27, 2012 15:03
-
-
Save rutger1140/3794491 to your computer and use it in GitHub Desktop.
Wordpress: filter on custom post type taxonomy in admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_restrict_manage_posts() { | |
global $typenow; | |
$args=array( 'public' => true, '_builtin' => false ); | |
$post_types = get_post_types($args); | |
if ( in_array($typenow, $post_types) ) { | |
$filters = get_object_taxonomies($typenow); | |
foreach ($filters as $tax_slug) { | |
$tax_obj = get_taxonomy($tax_slug); | |
wp_dropdown_categories(array( | |
'show_option_all' => __('Show All '.$tax_obj->label ), | |
'taxonomy' => $tax_slug, | |
'name' => $tax_obj->name, | |
'orderby' => 'term_order', | |
'selected' => $_GET[$tax_obj->query_var], | |
'hierarchical' => $tax_obj->hierarchical, | |
'show_count' => false, | |
'hide_empty' => true | |
)); | |
} | |
} | |
} | |
function my_convert_restrict($query) { | |
global $pagenow; | |
global $typenow; | |
if ($pagenow=='edit.php') { | |
$filters = get_object_taxonomies($typenow); | |
foreach ($filters as $tax_slug) { | |
$var = &$query->query_vars[$tax_slug]; | |
if ( isset($var) ) { | |
$term = get_term_by('id',$var,$tax_slug); | |
$var = $term->slug; | |
} | |
} | |
} | |
} | |
add_action('restrict_manage_posts', 'my_restrict_manage_posts' ); | |
add_filter('parse_query','my_convert_restrict'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment