• Leo Blanchette

    (@leoclipartillustrationcom)


    taxonomy_1 term = gold
    taxonomy_2 term = gold

    Generates 404 on taxonomy_2 because the slug has been named “gold-2

    Obviously this should not happen. What would cause this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Andrew Bartel

    (@andrew-bartel)

    Slugs are unique unfortunately, even if they have different parents.

    Thread Starter Leo Blanchette

    (@leoclipartillustrationcom)

    So maybe in category creation there is a way to force-uniqueness?

    Thread Starter Leo Blanchette

    (@leoclipartillustrationcom)

    Understandably this is a hard problem. I think I’ll just modify the slug as its being written that way there is no clashes.

    What is the hook for slug-writing in a custom taxonomy?
    Can’t seem to find it.

    Thread Starter Leo Blanchette

    (@leoclipartillustrationcom)

    This ended being the solution – to avoid my custom taxonomy clashing with my other taxonomy (and the users are very likely to make clashing/like terms) I did this – simply altered the slug of the category term to have an appropriate suffix that would keep unique from other taxonomies.

    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 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Slug Clash – Custom Taxonomy’ is closed to new replies.