I'm working on a site with custom post types and taxonomies and I have noticed a problem. When the following taxonomies are added in functions.php, its breaks the media insert dialog, only in a post, custom post, or page, not the actual media section in admin. So if I then want to set a featured image for a page, when I choose media library in the dialog to choose an already uploaded image, it says how many images there are but none are displayed. If I remove the taxonomy code, it works fine. Code is below.
add_action( 'init', 'create_workshops_taxonomies', 0 );
function create_workshops_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Workshop Venues', 'taxonomy general name' ),
'singular_name' => _x( 'Venue', 'taxonomy singular name' ),
'search_items' => __( 'Search Venues' ),
'all_items' => __( 'All Venues' ),
'parent_item' => __( 'Parent Venues' ),
'parent_item_colon' => __( 'Parent Venue:' ),
'edit_item' => __( 'Edit Venue' ),
'update_item' => __( 'Update Venue' ),
'add_new_item' => __( 'Add New Venue' ),
'new_item_name' => __( 'New Venue Name' ),
);
register_taxonomy('venue',array('workshops'),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'venue' ),
));
$labels = array(
'name' => _x( 'Workshop Types', 'taxonomy general name' ),
'singular_name' => _x( 'Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Types' ),
'all_items' => __( 'All Types' ),
'parent_item' => __( 'Parent Types' ),
'parent_item_colon' => __( 'Parent Type:' ),
'edit_item' => __( 'Edit Type' ),
'update_item' => __( 'Update Type' ),
'add_new_item' => __( 'Add New Type' ),
'new_item_name' => __( 'New Type Name' ),
);
register_taxonomy('type',array('workshops'),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'type' ),
));
$labels = array(
'name' => _x( 'Workshop Times', 'taxonomy general name' ),
'singular_name' => _x( 'Time', 'taxonomy singular name' ),
'search_items' => __( 'Search Times' ),
'all_items' => __( 'All Times' ),
'parent_item' => __( 'Parent Times' ),
'parent_item_colon' => __( 'Parent Time:' ),
'edit_item' => __( 'Edit Time' ),
'update_item' => __( 'Update Time' ),
'add_new_item' => __( 'Add New Time' ),
'new_item_name' => __( 'New Time Name' ),
);
register_taxonomy('time',array('workshops'),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'time' ),
));
$labels = array(
'name' => _x( 'Workshop Status', 'taxonomy general name' ),
'singular_name' => _x( 'Status', 'taxonomy singular name' ),
'search_items' => __( 'Search Status' ),
'all_items' => __( 'All Status' ),
'parent_item' => __( 'Parent Status' ),
'parent_item_colon' => __( 'Parent Status:' ),
'edit_item' => __( 'Edit Status' ),
'update_item' => __( 'Update Status' ),
'add_new_item' => __( 'Add New Status' ),
'new_item_name' => __( 'New Status Name' ),
);
register_taxonomy('status',array('workshops'),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'status' ),
));
}
wjm answers:
I assume you are using the custom post types "workshops"
if not, you are doing something wrong.
It has to do with this line
register_taxonomy('type',array('post'),
you are using a reserved word (type)
change it to something else, something like workshop_type
register_taxonomy('workshop_type',array('post'),
it should work
let me know if it doesnt.
- wjm
wjm comments:
sorry, it should be
register_taxonomy('workshop_type',array('workshops'),
i changed workshops for post for testing it.
James Beardmore comments:
Turns out I was mistaken, that didnt fix my problem, in fact, it broke the entire site! Looking at various tutorials including the WP codex, its clear that it was correct in having
register_taxonomy('type',array('workshops'),
And not
register_taxonomy('type',array('workshops'),
It turned out that the actual problem was from using "type" as a taxonomy term. Its obviously used somewhere else in the WP core and was ocnflicting with the media uploader. I changed it and now all is well.
James Beardmore comments:
Sorry meant to say that it is supposed to be
register_taxonomy('type',array('workshops'),
and not
register_taxonomy('workshop_type',array('workshops'),
Milan Petrovic answers:
You must not set priority for this init action to 0, or you might initialize your taxonomies (and custom post types) before WP defaults. I am author of GD Custom Posts and Taxonomies Tools plugin, and I use priority 1 for custom post types, and 2 for taxonomies to avoid WP conflicts.
So use this:
<blockquote>add_action( 'init', 'create_workshops_taxonomies', 2 );</blockquote>
And taxonomies should be added when they don't cause problems. Most likely your upload problems are caused by that. Also, I didn't check your full code, it too long, but my guess is this. And I recommend that you try my plugin and avoid problems with adding this bulky code to functions.php.
James Beardmore comments:
Nope that didn't do it. I'll definitely take a look at the plugin, I've heard lots of good things about it. However I still want to solve this for my own education.
James Beardmore comments:
Nope that didn't do it. I'll definitely take a look at the plugin, I've heard lots of good things about it. However I still want to solve this for my own education.