Last active
January 12, 2018 11:30
-
-
Save mankutila/fc5724e63139a0a2edf320988c35784c to your computer and use it in GitHub Desktop.
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 filter_projects_by_taxonomies( $post_type, $which ) { | |
if ( 'project' !== $post_type ) //your post type name instead of 'project' | |
return; | |
$taxonomies = array( 'type' ); //your post type taxonomy name instead of 'type' | |
foreach ( $taxonomies as $taxonomy_slug ) { | |
$taxonomy_obj = get_taxonomy( $taxonomy_slug ); | |
$taxonomy_name = $taxonomy_obj->labels->name; | |
$terms = get_terms( $taxonomy_slug ); | |
echo "<select name='{$taxonomy_slug}' id='{$taxonomy_slug}' class='postform'>"; | |
echo '<option value="">' . sprintf( esc_html__( 'Все %s', 'text_domain' ), $taxonomy_name ) . '</option>'; | |
foreach ( $terms as $term ) { | |
printf( | |
'<option value="%1$s" %2$s>%3$s (%4$s)</option>', | |
$term->slug, | |
( ( isset( $_GET[$taxonomy_slug] ) && ( $_GET[$taxonomy_slug] == $term->slug ) ) ? ' selected="selected"' : '' ), | |
$term->name, | |
$term->count | |
); | |
} | |
echo '</select>'; | |
} | |
} | |
add_action( 'restrict_manage_posts', 'filter_projects_by_taxonomies' , 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment