Update WP importer to use taxonomy and query cat based on slug. see #4613

git-svn-id: https://develop.svn.wordpress.org/trunk@5937 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2007-08-24 14:44:26 +00:00
parent 73d5479b43
commit aa0ab82ecd
3 changed files with 18 additions and 5 deletions

View File

@ -220,7 +220,7 @@ class WP_Import {
function process_categories() {
global $wpdb;
$cat_names = (array) $wpdb->get_col("SELECT cat_name FROM $wpdb->categories");
$cat_names = (array) get_terms('category', 'fields=names');
while ( $c = array_shift($this->categories) ) {
$cat_name = trim($this->get_tag( $c, 'wp:cat_name' ));
@ -323,8 +323,13 @@ class WP_Import {
if (count($categories) > 0) {
$post_cats = array();
foreach ($categories as $category) {
$cat_ID = (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name = '$category'");
$slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
$cat = get_term_by('slug', $slug, 'category');
$cat_ID = 0;
if ( ! empty($cat) )
$cat_ID = $cat->term_id;
if ($cat_ID == 0) {
$category = $wpdb->escape($category);
$cat_ID = wp_insert_category(array('cat_name' => $category));
}
$post_cats[] = $cat_ID;

View File

@ -35,6 +35,12 @@ foreach ( $filters as $filter ) {
add_filter($filter, 'wp_filter_kses');
}
// Slugs
$filters = array('pre_term_slug');
foreach ( $filters as $filter ) {
add_filter($filter, 'sanitize_title');
}
// Places to balance tags on input
$filters = array('content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content');
foreach ( $filters as $filter ) {

View File

@ -282,7 +282,7 @@ function &get_term(&$term, $taxonomy, $output = OBJECT, $filter = 'raw') {
* This won't appear but just a note to say that this is all conjecture and parts or whole
* might be inaccurate or wrong.
*/
function get_term_by($field, $value, $taxonomy, $output = OBJECT) {
function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {
global $wpdb;
if ( ! is_taxonomy($taxonomy) )
@ -307,6 +307,8 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT) {
wp_cache_add($term->term_id, $term, $taxonomy);
$term = sanitize_term($term, $taxonomy, $filter);
if ( $output == OBJECT ) {
return $term;
} elseif ( $output == ARRAY_A ) {
@ -487,6 +489,8 @@ function &get_terms($taxonomies, $args = '') {
$select_this = 't.*, tt.*';
else if ( 'ids' == $fields )
$select_this = 't.term_id';
else if ( 'names' == $fields )
$select_this == 't.name';
$query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number";
@ -771,8 +775,6 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
if ( empty($slug) )
$slug = sanitize_title($name);
else
$slug = sanitize_title($slug);
$term_group = 0;
if ( $alias_of ) {