I have an array with the categories and sub-categories I want to import to the "campsite-district-county" taxonomy. My sub-categories are not being inserted with the correct parent. They're being inserted on the root level. After some investigation I come across the information that I needed to clear the taxonomy cache after each insert, so I did but I still have the same problem.

$dist[]=array('Açores','Angra do Heroísmo');
foreach($dist as $d) {
    if(is_array($d)) {
        if ($parent_term=term_exists(trim($d[0]), 'campsite-district-county')) {
            //do nothing - let's add the county bellow
        } else {
            //Adds district
            $parent_term=wp_insert_term(trim($d[0]), 'campsite-district-county');
            echo '<h1>'.trim($d[0]).'</h1>';

        echo '<p>*'.$id_parent.'*</p>';
        //Add county
        $child_term=wp_insert_term(trim($d[1]), 'campsite-district-county', array('parent', $id_parent));
        echo '<p>'.trim($d[1]).'</p>';

1 Answer 1


You have error in your PHP. This array('parent', $id_parent) will produce numeric array with two values - string parent and value of $id_parent.

What you actually need is array( 'parent' => $id_parent ) which will produce correct associative array with one entry of key parent and value $id_parent.

  • I was just going to delete this post because I found out the error. THANKS! May 8, 2013 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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