• Resolved ddimaria

    (@ddimaria)


    I’m having issues when there is a comma in the category name. The system adds the category in as separate categories. For example, in the csv file I have the following entry:

    “Toddler > Toddler Health & Safety > Heath, Complications, & Illness > Autism, ADD, & ADHD”

    Here, “Heath, Complications, & Illness” gets converted into 3 separate categories:

    Health
    Complications
    & Illness

    I’ll try to create a patch for this, but if anyone already has please post. Thanks! -David

    http://wordpress.org/extend/plugins/csv-importer/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter ddimaria

    (@ddimaria)

    I traced out the code, and it looks like the code is good. Below is the array I traced out in the create_or_get_categories function. So, it looks like the issue is related to WP’s wp_insert_category function.

    Array
    (
    [0] => Array
    (
    [cat_name] => Toddler
    [category_parent] =>
    )

    [1] => Array
    (
    [cat_name] => Toddler Health & Safety
    [category_parent] =>
    )

    [2] => Array
    (
    [cat_name] => Heath, Complications, & Illness
    [category_parent] =>
    )

    [3] => Array
    (
    [cat_name] => Autism, ADD, & ADHD
    [category_parent] =>
    )

    )

    Thread Starter ddimaria

    (@ddimaria)

    So, it looks like this is a “feature” of the core. If you look at line 2651 of wp-includes/taxonomy.php:

    $object_ids = explode(‘,’, $object_ids);

    It looks like a hack to the importer is needed to alter to comma prior to injection (maybe [COMMA] or like), then update the terms table after the import is complete. This is assuming that you can have commas in category names in WP.

    Thread Starter ddimaria

    (@ddimaria)

    I spoke too soon, the problem is with line 301 of the plugin:

    $items = array_map(‘trim’, explode(‘,’, $data[‘csv_post_categories’]));

    I’m not sure why this is in place, but when I replace it with the below code, the categories imported properly:

    $items = array_map(‘trim’, array( $data[‘csv_post_categories’]) );

    Thread Starter ddimaria

    (@ddimaria)

    As a final post, here’s what I ended up doing to preserve the ability to import multiple categories for a single post with commas in the category name:

    $items = array_map(‘trim’, explode(‘|’, $data[‘csv_post_categories’]));

    I just changed the delimiter to a pipe. It’s a hack, but works for my purposes.

    I had the same problem,

    $items = array_map('trim', explode('|', $data['csv_post_categories']));

    helped. Thank you, ddimaria, that’s a good idea.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: CSV Importer] Comma in csv_post_categories’ is closed to new replies.