[wp-trac] [WordPress Trac] #10122: create metaboxes for hierarchical taxonomies
WordPress Trac
wp-trac at lists.automattic.com
Sat Apr 24 02:27:07 UTC 2010
#10122: create metaboxes for hierarchical taxonomies
-----------------------------+----------------------------------------------
Reporter: nicomollet | Owner: ryan
Type: feature request | Status: reopened
Priority: normal | Milestone: 3.0
Component: Taxonomy | Version: 2.8
Severity: minor | Resolution:
Keywords: needs-patch |
-----------------------------+----------------------------------------------
Comment(by dd32):
I was originally going to add this to the metabox:
{{{
$name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' .
$taxonomy . ']';
echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for
an empty term set to be sent. 0 is an invalid Term ID.
}}}
That'd have worked and done the job..
But handling it properly in wp_insert_post() is probably better.
{{{
if ( isset($tax_input[$tax_name]) )
$term = $tax_input[$tax_name];
elseif ( $tax_obj->show_ui )
$term = array();
else
continue;
}}}
I dont like that for one particlar reason, tax_input will only be set by
show_ui, if a plugin sets it itself with a custom div, then they'll have
to hack around this bug themselves by including a 0 term_id.
Its probably best to have a clear-cut working functionality, Any
automatically added metaboxes will work as expected, but if a plugin adds
a custom taxonomy div, they'll have to handle all the term saving..
This is a version i've come up with based off scribu's patch:
{{{
// new-style support for all taxonomies
$tax_names = get_object_taxonomies( get_post($post_ID) );
foreach ( (array)$tax_names as $taxonomy ) {
$taxonomy_obj = get_taxonomy($taxonomy);
if ( !current_user_can($taxonomy_obj->show_ui) )
continue;
if ( !current_user_can($taxonomy_obj->assign_cap) )
continue;
$tags = isset($tax_input[$taxonomy]) ?
$tax_input[$taxonomy] : array();
wp_set_post_terms( $post_ID, $tags, $taxonomy );
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10122#comment:40>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list