Custom Taxonomy Slug Hook? [closed]

♀尐吖头ヾ 提交于 2019-12-12 03:49:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!