| | 579 | } |
|---|
| | 580 | |
|---|
| | 581 | // Convert categories to terms. |
|---|
| | 582 | $tt_ids = array(); |
|---|
| | 583 | $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories"); |
|---|
| | 584 | foreach ($categories as $category) { |
|---|
| | 585 | $term_id = (int) $category->cat_ID; |
|---|
| | 586 | $name = $wpdb->escape($category->cat_name); |
|---|
| | 587 | $description = $wpdb->escape($category->category_description); |
|---|
| | 588 | $slug = $wpdb->escape($category->category_nicename); |
|---|
| | 589 | $parent = $wpdb->escape($category->category_parent); |
|---|
| | 590 | $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('$term_id', '$name', '$slug', '$term_group')"); |
|---|
| | 591 | |
|---|
| | 592 | if ( !empty($category->category_count) ) { |
|---|
| | 593 | $count = (int) $category->category_count; |
|---|
| | 594 | $taxonomy = 'category'; |
|---|
| | 595 | $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); |
|---|
| | 596 | $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; |
|---|
| | 597 | } else if ( !empty($category->link_count) ) { |
|---|
| | 598 | $count = (int) $category->link_count; |
|---|
| | 599 | $taxonomy = 'link_category'; |
|---|
| | 600 | $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); |
|---|
| | 601 | $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; |
|---|
| | 602 | } else if ( !empty($category->tag_count) ) { |
|---|
| | 603 | $count = (int) $category->tag_count; |
|---|
| | 604 | $taxonomy = 'post_tag'; |
|---|
| | 605 | $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); |
|---|
| | 606 | $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; |
|---|
| | 607 | } else { |
|---|
| | 608 | $count = 0; |
|---|
| | 609 | $taxonomy = 'category'; |
|---|
| | 610 | $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); |
|---|
| | 611 | $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; |
|---|
| | 612 | } |
|---|
| | 613 | } |
|---|
| | 614 | |
|---|
| | 615 | $posts = $wpdb->get_results("SELECT * FROM $wpdb->post2cat"); |
|---|
| | 616 | foreach ( $posts as $post ) { |
|---|
| | 617 | $post_id = (int) $post->post_id; |
|---|
| | 618 | $term_id = (int) $post->category_id; |
|---|
| | 619 | $taxonomy = 'category'; |
|---|
| | 620 | if ( !empty($post->rel_type) && 'tag' == $post->rel_type) |
|---|
| | 621 | $taxonomy = 'tag'; |
|---|
| | 622 | $tt_id = $tt_ids[$term_id][$taxonomy]; |
|---|
| | 623 | if ( empty($tt_id) ) |
|---|
| | 624 | continue; |
|---|
| | 625 | |
|---|
| | 626 | $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post_id', '$tt_id')"); |
|---|
| | 627 | } |
|---|
| | 628 | |
|---|
| | 629 | $links = $wpdb->get_results("SELECT * FROM $wpdb->link2cat"); |
|---|
| | 630 | foreach ( $links as $link ) { |
|---|
| | 631 | $link_id = (int) $link->link_id; |
|---|
| | 632 | $term_id = (int) $link->category_id; |
|---|
| | 633 | $taxonomy = 'link_category'; |
|---|
| | 634 | $tt_id = $tt_ids[$term_id][$taxonomy]; |
|---|
| | 635 | if ( empty($tt_id) ) |
|---|
| | 636 | continue; |
|---|
| | 637 | |
|---|
| | 638 | $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$link_id', '$tt_id')"); |
|---|