Sep
26

wp_dropdown_categories with taxonomies

WordPress  

This is one for other developers.  Until this bug 13258 is fixed, if you are trying to get the wordpress function wp_dropdown_categories() to work with custom taxonomies, then you may need custom code.

Attached is a sample file.  The code is based on code from somewhere else, but I forget where.  I had to do even more funky things like swop the default url out for an “events” url so that the query would deliver event posts ordered by event instance date rather than published date.  See that in action at icalevents test site

I have stripped that back, so I think the attached file is all you need now.  I am using it for another private plugin which is adding filtering to the manage posts admin page and it seems to work ok.

Zipped file: amr-custom-dropdown-taxonomy

Note: the taxonomy being used here is called “plugin_categories” – it NOT using categories.

Custom filter

The filtered result

the url

Related posts:

  1. Permalinks, custom post types and taxonomies, conflicts How to avoid clash, conflict and 404 problems with permalinks, custom post types and taxonomies....
  2. How to give your plugin pluggable functions How to give your plugin pluggable functions and how to override a pluggable function by defining your own....
  3. Why I code without javascript if i can Developing without javascript - why?...
Categories : WordPress

4 Comments

1

sorry but I really don’t understand where I have to use your piece of code and how.
Could you explain it a bit?

thanks.

2

federico,

this is for people writing plugins or themes and who find that the wordpress function wp_dropdown_categories() is not delivering the custom taxonomies the way that they want, then they can use the attached code and call those functions instead. So they would include the code in theirs and call the function inside instead of wordpress function wp_dropdown_categories().

It is not a plugin itself, just a code sample.

3

ok, that was already clear.
I already placed the code in my functions.php file, used the function amr_dropdown_taxonomy_terms() instead of wp_dropdown_categories() in a custom template file.
I recon that now, I have to setup the parameters, but my custom taxonomy is associated with a custom post type, will it be a problem?
I’m trying to set up the parameters:
$defaults = array(
‘show_option_all’ => ”,
‘show_option_none’ => ”,
‘orderby’ => ‘id’,
‘order’ => ‘ASC’,
‘show_last_update’ => 0,
‘show_count’ => 0,
‘hide_empty’ => 1,
‘child_of’ => 0,
‘exclude’ => ”,
‘echo’ => 1,
‘selected’ => 0,
‘hierarchical’ => 0,
‘name’ => ‘cat’,
‘class’ => ‘postform’,
‘depth’ => 0,
‘tab_index’ => 0,
‘taxonomy’ => ‘Scuole’
);

but it’s not working.

4

with this conf I get the regular category, but I can’t display my custom taxonomy ‘Scuole’…

$defaults = array(
‘show_option_none’ => ‘Scuola’,
‘orderby’ => ‘id’,
‘order’ => ‘ASC’,
‘show_last_update’ => 0,
‘show_count’ => 0,
‘hide_empty’ => 1,
‘child_of’ => 0,
‘exclude’ => ”,
‘echo’ => 1,
‘selected’ => 0,
‘hierarchical’ => 0,
‘name’ => ‘scuola’,
‘class’ => ‘postform’,
‘depth’ => 0,
‘tab_index’ => 4,
‘taxonomy’ => ‘category’
);

WP Questions

Preferred Web Host

Web hosting by ICDSoft Icdsoft - Why? They are good and reasonable, used them since 2001. Read more