elin-r
12/5/2016 - 7:21 PM

WP Admin Sort Custom Post Type Taxonomies Dropdown Replace function names, post type and taxonomy name and put in functions.php of child the

WP Admin Sort Custom Post Type Taxonomies Dropdown Replace function names, post type and taxonomy name and put in functions.php of child theme – https://pippinsplugins.com/post-list-filters-for-custom-taxonomies-in-manage-posts/

// Sortera bland titeltyper i månadsmail

function add_taxonomy_filters() {
	global $typenow;
 
	// an array of all the taxonomyies you want to display. Use the taxonomy name or slug
	$taxonomies = array('titeltyp');
 
	// must set this to the post type you want the filter(s) displayed on
	if( $typenow == 'manadsmail' ){
 
		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=''>Visa alla titlar / typer</option>";
				foreach ($terms as $term) { 
					echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>'; 
				}
				echo "</select>";
			}
		}
	}
}
add_action( 'restrict_manage_posts', 'add_taxonomy_filters' );