WP_INSERT_TERM不适用于自定义发布类型的税收

时间:2016-05-26 作者:user2235208

以下是我遇到的问题:

I have a custom post type called "developer"
This custom post type "developers" has a custom taxonomy, "developer", hierarchic
I want to programmatically insert into this custom taxonomy "developer" 2 terms
下面是我用来插入一个术语的函数和操作:

// programatically add terms to the taxonomy "developer"
function autoset_post_developer(&$post, $developer)
{
    if(empty($developer)) return;
    $cat    = get_cat_ID($developer);
    if(!$cat)
    {
        $cat    = wp_insert_term($developer, \'developer\', array(
            \'description\' => \'\' . $developer,
            \'slug\' => sanitize_title($developer)
        ));
        $cat    = $cat[\'term_id\'];
    }
    if($cat)
    {
        $post[\'post_developer\'] = array($cat);
    }
}
问题:wp\\u insert\\u term似乎不适用于我的自定义分类法

1 个回复
SO网友:vancoder

代码中的问题更严重。

$cat    = get_cat_ID($developer);
对于自定义分类法,将返回false,因为它只检查标准类别。

使用get_term_by 相反

相关推荐