Skip Navigation

Import Content Using CSV Importer Plugin in WordPress

This lesson shows how to import site content using Types and the CSV Importer plugins.

Requirements and important notes

Before explaining the process of importing data using CSV files, it is important to consider the following information.

Field Types That Are Not Supported

You will not be able to import any data stored as serialized array in your database. This includes:

  • Checkboxes
  • 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.

Importing Date Fields

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.

All Values Must be Escaped

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.

Mandatory Columns

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.

Column Prefixes

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.

Data Coming From Third Parties

All of the third party data (coming from other plugins or themes) might be in a different format. We can not control that.

Importing Large Databases

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.

Importing Types Post Relations

Toolset allows you to import post relationship information and associations using CSV files.

Forum Support For Topics Regarding Importing Data Is Limited

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.

CSV Importer Provides Many Examples

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.

Case Example

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 Provided Example

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

Formatting Of The Provided Example

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.

CSV file needs to have column headings (e.g. meta keys) on the first row
CSV file needs to have column headings (i.e. meta keys) on the first row

The following table lists post values provided in the attached sample file.

Content Type Value
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
Types Field Phone 077223344
WordPress native Category Term category-term
WordPress Post Type consultants

Steps To Import The Data

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.

1. Create The Custom Post Type

Use Types plugin to create your new custom content types. If this is your first time using Types, you can find step-by-step instructions in the lesson on creating custom post types.

In this example, you need to create a custom post type called “Consultants” and use the standard WordPress “Category” for its taxonomy.

2. Create The Post Fields

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 lesson 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.

3. Create The CSV File

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.

Import your CSV File and Create WordPress Content

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!

  1. In WordPress admin, go to Tools->CSV Importer.
  2. Click Browse and navigate to your CSV file.
  3. Do not check the Import posts as drafts or Organize into category options.
  4. Click Import.

Once the importer completes, you will have the new Consultants data.

Displaying the Imported Content

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.

Blocks 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 Blocks. 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.

November 16, 2020