WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>';
share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer
I was just going to delete this post because I found out the error. THANKS! – Marco Almeida May 8 '13 at 20:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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