• Does anyone know of a way to add multiple categories at once instead of one at a time? (maybe by import or a plugin)

    I created a parent category and now I want to create about 100 categories under that.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Could try this:

    <?php
    //import categories from csv
    //sample data for $import_file category,category parent,slug,description
    //Parent categories must be in file before child categories
    //
    //"county1",""
    //"county2",""
    //"city1","county1"
    //"city2","county2"
    //"city3","county1"
    //"county3",""
    //"County Cork","","county cork","county cork descripiton of this cat"
    //"County Morefields","","","This is description of county morefields"
    
    require_once(ABSPATH . "wp-admin/includes/admin.php");
    $import_file = TEMPLATEPATH . '/cat.txt';
    $import = array();
    $fh = fopen($import_file,'r');
    while($t = fgetcsv($fh)) {
        $import[] = $t;
    }
    
    foreach ($import as $importcat) {
      $numfields=count($importcat);
      $cat_ID = get_cat_ID($importcat[0]);
      $cat_name = $importcat[0];
      $category_parent = get_cat_ID($importcat[1]);
    
      if ($numfields > 2)
        $category_nicename = sanitize_title($importcat[2]);
    
      if ($numfields > 3)
        $category_description = $importcat[3];
    
      $args = compact('cat_ID', 'cat_name', 'category_description', 'category_nicename', 'category_parent');
      wp_insert_category($args);
    }
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Batch Category Add’ is closed to new replies.