Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
$dist[]=array('Açores','Corvo');
$dist[]=array('Aveiro','Águeda');
$dist[]=array('Aveiro','Anadia');
foreach($dist as $d) {
    $i++;
    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');
            delete_option("campsite-district-county");
            wp_cache_flush();
            echo '<h1>'.trim($d[0]).'</h1>';

        }
        $id_parent=intval($parent_term['term_id']);
        echo '<p>*'.$id_parent.'*</p>';
        //Add county
        $child_term=wp_insert_term(trim($d[1]), 'campsite-district-county', array('parent', $id_parent));
        delete_option("campsite-district-county_children");
        wp_cache_flush();
        echo '<p>'.trim($d[1]).'</p>';
    }
}
share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.