问题
To avoid naming issues I decided to attempt to change the url slug as its being submitted, by appending a "unique-to-taxonomy" suffix.
What is the hook for doing something like this? How would it be used?
回答1:
I did find a good way around things:
Problem: Like-slugs will clash and produce 404's in different taxonomies. My theme is extremely keyword and category heavy, and my users are not incredibly wordpress savvy. So clashes cannot be allowed.
Upon submission of a new category either in the custom tax area or the custom post area, the taxonomy is changed to be unique to the custom-taxonomy and clash-proof
function symbiostock_unique_category( $term_id, $tt_id, $taxonomy )
{
if ( $taxonomy == 'image-type' ) {
if ( isset( $_POST[ 'slug' ] ) && !empty( $_POST[ 'slug' ] ) ) {
$name = sanitize_title( $_POST[ 'slug' ] ) . '-images';
} elseif ( isset( $_POST[ 'tag-name' ] ) && !empty( $_POST[ 'tag-name' ] ) ) {
$name = sanitize_title( $_POST[ 'tag-name' ] ) . '-images';
} elseif ( isset( $_POST[ 'newimage-type' ] ) && !empty( $_POST[ 'newimage-type' ] ) ) {
$name = sanitize_title( $_POST[ 'newimage-type' ] ) . '-images';
}
wp_update_term( $term_id, $taxonomy, array(
'slug' => $name
) );
}
}
add_action( 'create_term', 'symbiostock_unique_category', 10, 3 );
来源:https://stackoverflow.com/questions/15777177/custom-taxonomy-slug-hook