WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How could I import a list of new categories and category descriptions from a file of Comma Separated Values?

share|improve this question
You hav a csv file, and you want that for your category description ? – amit Jul 9 '12 at 5:27
What do you mean? The categories already exist and you want to import only descriptions? Please, add more details to your Question... Oh, yes, welcome to WPSE and remember to read the FAQ :) – brasofilo Jul 9 '12 at 8:26

Very simple plugin to achieve this.

Runs only on activation, so, if there are 5 CSV files, the plugin must be activated/deactivated five times.



    Plugin Name: Insert CSV Categories
    Version: 1.0
    Description: Reads a CSV file on plugin activation and insert the Categories/Description/Parent into WordPress as defined in the CSV
    Plugin URI: http://wordpress.stackexchange.com/q/57865/12615
    Author: brasofilo 
    Author URI: http://rodbuaiz.com
register_activation_hook(__FILE__, 'wpse_57865_activation_run');

function wpse_57865_activation_run()
    // Code snippet: http://stackoverflow.com/q/7502370/1287812
    $file = file_get_contents( plugin_dir_path( __FILE__ )  . 'categories.csv' );
    $data = array_map( "str_getcsv", preg_split( '/\r*\n+|\r+/', $file ) );

    if( count($data) < 1)

    // http://codex.wordpress.org/Function_Reference/wp_insert_category
    foreach( $data as $cat )
        $cat_defaults = array(
          'cat_name' => $cat[0],
          'category_description' => $cat[1] 





Category Title, Category Description
First Category, Lorem ipsum dolor sit amet
Second Category, Consectetur adipisicing elit
Third Category, Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
share|improve this answer
i think you should update this code to use php.net/manual/en/function.fgetcsv.php instead of preg split - you don't have to map it - simply read line after line. – Łukasz Rysiak Jul 28 '13 at 19:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.