[wp-hackers] Custom Post Type in Admin, filter by new custom Taxonomies

Mike Schinkel mikeschinkel at newclarity.net
Fri Jul 23 06:45:36 UTC 2010

> 2010/7/23 scribu <scribu at gmail.com>

>> On Fri, Jul 23, 2010 at 6:59 AM, Jimmy Roy <jimmy.roy at gmail.com> wrote:
>>> hi all,
>>> I've create a custom post type (Ressource) and a custom taxomomies,
>>> everything works well but it miss something in the admin, in regular Post
>>> Type, when I list all the Post in admin I can filter by categories, but I
>>> dont have this select box in my custom post type page (the pas wich list
>>> all
>>> my Ressource post).
>>> is it possible to get it ?
>> Yes, it's possible, but you'll have to output it in the footer and then use
>> jQuery to place it above the table.

Are you sure?  Unless I misunderstand what Jimmy is asking I think it can be done in the "restrict_manage_posts" hook.  Jimmy, try this in your theme's functions.php file changing the name of the post type and the name of the taxonomy (let us know if this is what you need or not):


		function my_restrict_manage_posts() {
			global $typenow; 
			if ($typenow=='your_custom_type')
				echo get_taxonomy_html_select('your_taxonomy');

		function get_taxonomy_html_select($taxonomy_name) {
			$taxonomy = get_taxonomy($taxonomy_name);
			$terms = get_terms($taxonomy_name);
			$label = __("Show All {$taxonomy->label}");
			$html = array();
			$html[] = "<select id=\"$taxonomy_name\" name=\"$taxonomy_name\">";
			$html[] = "<option value=\"0\">$label</option>";
			$this_term = $_GET[$taxonomy_name];
			foreach($terms as $term) {
				$default = ($this_term==$term->term_id ? ' selected="selected"' : '');
				$value = esc_attr($term->name);
				$html[] = "<option value=\"{$term->term_id}\"$default>$value</option>";
			$html[] = "</select>";
			return implode("\n",$html);

> I don't understand why it's not standard.

(In my opinion) it's because WordPress like any (open-source) software is alway in an evolution.  WordPress has just evolved to have Custom Post Types but it will take time to identify all the important related core and usage patterns and have them applied to WordPress core.


More information about the wp-hackers mailing list