WordPress.org

Ready to get started?Download WordPress

Forums

CSV Importer
[resolved] Comma in csv_post_categories (6 posts)

  1. ddimaria
    Member
    Posted 2 years ago #

    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/

  2. ddimaria
    Member
    Posted 2 years ago #

    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] =>
    )

    )

  3. ddimaria
    Member
    Posted 2 years ago #

    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.

  4. ddimaria
    Member
    Posted 2 years ago #

    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']) );

  5. ddimaria
    Member
    Posted 2 years ago #

    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.

  6. Erida
    Member
    Posted 1 year ago #

    I had the same problem,

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

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic