Git Product home page Git Product logo

advanced-csv-importer's Introduction

advanced-csv-importer

Build Status

Import posts, pages, custom fields, categories, tags and more from a CSV file.

Advanced CSV Importer is fully unit-tested. The plugin is stable and ready to be used in large projects like enterprise applications.

WP-CLI support

Importing CSV

$ wp csv import tests/_data/wp/sample.csv
+------+-----------------------+------+---------+------------+---------------------+
| ID   | Title                 | Type | Status  | Author     | Date                |
+------+-----------------------+------+---------+------------+---------------------+
| 1720 | CSV Import Test       | post | publish | admin      | 2013-09-13 00:00:00 |
| 1721 | define author test    | post | publish | admin      | 2014-12-27 18:44:46 |
| 1722 | define author id test | post | publish | themedemos | 2014-12-27 18:44:46 |
| 1    | Hello world! Updated! | post | publish | admin      | 2014-12-27 18:44:46 |
+------+-----------------------+------+---------+------------+---------------------+

History

$ wp csv log
+----------+-----------------------------+---------------------+---------+---------+
| ID       | Title                       | Date                | Success | Failure |
+----------+-----------------------------+---------------------+---------+---------+
| e0a66344 | Imported from WP-CLI.       | 2014-12-27 18:44:46 |       4 |       0 |
| 43c47af6 | Imported from admin screen. | 2014-12-27 16:53:17 |       4 |       0 |
| df0f140b | Imported from WP-CLI.       | 2014-12-27 16:21:42 |       4 |       0 |
+----------+-----------------------------+---------------------+---------+---------+

Details of the history

$ wp csv log e0a66344
+------+-----------------------+------+---------+------------+---------------------+
| ID   | Title                 | Type | Status  | Author     | Date                |
+------+-----------------------+------+---------+------------+---------------------+
| 1720 | CSV Import Test       | post | publish | admin      | 2013-09-13 00:00:00 |
| 1721 | define author test    | post | publish | admin      | 2014-12-27 18:44:46 |
| 1722 | define author id test | post | publish | themedemos | 2014-12-27 18:44:46 |
| 1    | Hello world! Updated! | post | publish | admin      | 2014-12-27 18:44:46 |
+------+-----------------------+------+---------+------------+---------------------+

Delete imported posts

$ wp post delete $(wp csv log e0a66344 --format=ids)
Success: Trashed post 1720.
Success: Trashed post 1721.
Success: Trashed post 1722.
Success: Trashed post 1.

How to customize

Default CSV field names

  • ID
  • post_content
  • post_name
  • post_title
  • post_status
  • post_type
  • post_author
  • ping_status
  • post_parent
  • menu_order
  • to_ping
  • pinged
  • post_password
  • guid
  • post_content_filtered
  • post_excerpt
  • post_date
  • post_date_gmt
  • comment_status
  • post_category
  • tags_input
  • page_template

You can change field name via acsv_post_object_keys hook like following.

add_filter( 'acsv_post_object_keys', function( $post_object_keys ){
    $post_object_keys['title'] = 'post_title';
    $post_object_keys['content'] = 'post_content';
    return $post_object_keys;
} );

Other columns will be saved to the custom field.

Post thumbnail support

add_action( 'acsv_after_insert_post', function( $post_id, $post, $helper ){
    $id = $helper->add_media( $post['post_meta']['post_thumbnail'] );
    update_post_meta( $post_id, '_thumbnail_id', $id );
}, 10, 3 );

CSV format should be like below.

post_title,post_thumbnail
This is my cool photo!,http://example.com/path/to/photo.jpg

Converting charset

add_filter( 'acsv_csv_format', function( $format ){
    $format['from_charset'] = 'SJIS-win';
    return $format;
} );

Contributions

$ git clone [email protected]:miya0001/advanced-csv-importer.git
$ cd advanced-csv-importer
$ composer install

Running the phpunit.

$ bin/install-wp-tests.sh <db-name> <db-user> <db-pass> [db-host] [wp-version]

Then run tests.

$ phpunit

advanced-csv-importer's People

Contributors

miya0001 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.