Before explaining the process of importing data using CSV files, it is important to consider the following information.
You will not be able to import any data stored as serialized array in your database. This includes:
- Skype fields
- Repeatable items (because their sort order is stored as an array)
These types of post fields are not supported by the process outlined in this document. Custom coding or changing the field type is needed to import these field types.
The date field is a special kind of a field that uses timestamps to store the value. This is why its value in the CSV file also needs to be saved in the timestamp format.
Every CSV column name and every CSV column value must be escaped using the double-quotes.
You can use special characters such as commas or question marks in the CSV column values, but again, only if the values are escaped correctly.
Sample files found in the CSV Importer plugin’s folder (csv-importer->examples), as well as the example attached to this document, provide good examples of this.
Post Title, Post Type and Post Excerpt are mandatory. Post Title and Type and cannot be NULL or omitted while Post Excerpt can be empty.
The following rules are important regarding the prefixes for specific columns in the CSV file:
- Any column that does not start with csv_ is considered to be a custom field name.
- All native post data (basic post information) must feature the csv_ prefix.
- All slugs of post fields created with Types must be prefixed with wpcf-. The Types plugin adds this prefix automatically to your post field slug, but you must insert it into the CSV file manually.
All of the third party data (coming from other plugins or themes) might be in a different format. We can not control that.
If you import thousands of posts at a time, you might overload your servers capacities, like memory. Consider this if you run into problems when importing large databases.
If you want to import Types Post Relations, consider that the Parent Post ID is stored in a field called _wpcf_belongs_parent-post-slug_id. Its value is numerical.
Parent Post ID cannot be “guessed” by the system. You first need to create your parent post and get its ID. Then you can use that ID to import child posts.
Please note that the topic of importing data into WordPress using CSV usually falls out of the scope of our support forum. If needed, you can get help from one of our certified consultants.
- We do not offer support for issues with importing of serialized data.
- How you generate your CSV is up to you. We do not build, support or create the CSV Importer plugin and our supporters cannot help you generate these files.
- We do not offer support for issues caused by bad CSV file formatting. Please study the documentation of the CSV Importer plugin carefully.
- The importing process is done completely by the CSV Importer plugin, as it interacts with the database directly. The Types plugin cannot interrupt or break this process in any way. If you run into problems, you need to ensure is that all data is previously created with Types and you use the correct meta keys and slugs.
The CSV Importer plugin provides a huge set of examples in its root folder. Please refer to them for testing the process of importing the data.
For the purpose of this document, we prepared a simplified sample data saved as a CSV file. You can download it here.
Structure of the sample data is as follows:
- A post type with the slug consultants.
- This post type is also assigned to WordPress native categories.
- The data contains these post fields:
- Single Line fields slugs: name, street, city, state
- Number fields slugs: zip
- URL fields slugs: url
- Phone Fields slugs: phone
The CSV importer plugin, which you will be using to import all these contents, expects to see a very specific file format.
Data must be arranged into columns. The column headers will tell the importer what to do with each column.
All column headings should be on the first row (at cell A1). The file is created using any of the spreadsheet or text editing software and saved as comma delimited CSV file.
The following table lists post values provided in the attached sample file.
|Title||This is the Post Title|
|Post Body||This is the Post Body|
|Excerpt (CSV import Plugin requires an excerpt)||empty|
|Types field Name||This is wpcf-name|
|Types field Street||This is wpcf-street|
|Types field City||This is wpcf-city|
|Types Field ZIP||6001|
|Types Field State||This is wpcf-state|
|Types Field URL||https://url.com|
|Types Field Phone||077223344|
|WordPress native Category Term||category-term|
|WordPress Post Type||consultants|
Now that we covered the most important aspects of importing the database into a site, you can use the following steps to do this yourself.
In this example, you need to create a custom post type called “Consultants” and use the standard WordPress “Category” for its taxonomy.
Our example requires several post fields, to hold appropriate attributes. You need to create them too, using Types. Again, if this is your first time using Types, have a look at the tutorial on creating post fields.
First, create a group for the new post fields and in the group’s options, select to display it only for Consultants.
Next, start adding fields into this group according to the slugs and field types listed in the table above.
You need to make sure that there is a complete match between the heading names in the CSV file and the field slug names. The human field name does not matter for the importing process. The importer only sees the field slug value.
Now, you need to create the CSV file or use the attached one for testing purposes. Any preferred software can be used for this purpose, like spreadsheet and text editors.
The correct syntax is of utmost importance. To ensure this, consider the following rules:
- No values can be missing, but they can be empty if escaped using two double-quotes with nothing in between.
- No meta key can be missing and they must match the ones on the site.
- The post title, body and post type must hold a key and a value.
- The excerpt must hold a key but can have an empty value.
At this stage, you should have everything ready. Let’s just review and make sure:
- CSV file, with correct column headings, matching the names of each field.
- The custom post type and post fields created on the site.
- The CSV importer plugin activated in the site.
Now, you do the actual content import!
- In WordPress admin, go to Tools->CSV Importer.
- Click Browse and navigate to your CSV file.
- Do not check the Import posts as drafts or Organize into category options.
- Click Import.
Once the importer completes, you will have the new Consultants data.
Until now, we covered importing content into the WordPress database. You might be wondering how you can display it on your site.
Types is part of the Toolset family of plugins and is responsible for the WordPress admin. The other components will help you display content, control access to it and even allow visitors to edit from front-pages.
Views will let you display custom content in your site, in any way you choose. In our properties example, you can create property listings, property sliders and any other output type using Views. You can also customize the layout of individual property pages.
Forms allows you to build forms for creating and editing content from front-pages. This way, you can let site visitors submit new content or edit it. You can control which user types can submit new content, modify and delete.
And finally, Access plugin lets you control who can do what on your site.