自定义分类 Slug Hook? [英] Custom Taxonomy Slug Hook?

查看:29
本文介绍了自定义分类 Slug Hook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了避免命名问题,我决定尝试在提交时更改 url slug,方法是附加唯一分类法"后缀.

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?

推荐答案

我确实找到了解决问题的好方法:

I did find a good way around things:

问题:Like-slugs 会在不同的分类法中发生冲突并产生 404.我的主题是非常重的关键字和类别,而且我的用户对 wordpress 并不十分精通.所以不允许发生冲突.

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 );

这篇关于自定义分类 Slug Hook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆