Here is the problem I am having:

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

Here is the function and the action I am using to insert one term:

// programatically add terms to the taxonomy "developer"
function autoset_post_developer(&$post, $developer)
    if(empty($developer)) return;
    $cat    = get_cat_ID($developer);
        $cat    = wp_insert_term($developer, 'developer', array(
            'description' => '' . $developer,
            'slug' => sanitize_title($developer)
        $cat    = $cat['term_id'];
        $post['post_developer'] = array($cat);

The problem: wp_insert_term doesn't appear to be working with my custom taxonomy

  • What's the custom post type is it developers or developer ? – bravokeyl May 26 '16 at 9:43
  • register_taxonomy('developers' – user2235208 May 26 '16 at 9:49

The problem is higher in your code.

$cat    = get_cat_ID($developer);

will return false for a custom taxonomy, as it only checks the standard categories.

Use get_term_by instead.

|improve this answer|||||
  • give me any example – user2235208 Jun 6 '16 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.