In more than one occasion we will have to export and import content in WordPress, which might be a consequence of a modification/update or being connected to an external service which updates along with our content or which we download data from. The list of possible causes can be much longer, but without a doubt, somewhere along the line we will face this task.

I would like to point out that this is about elements from the content (pages, entries, comments, users, etc.), rather than migrating the whole web, in which case it's best to use a specific tool such as All-in-One WP Migration.

How to export and import content in WordPress

WordPress includes its own export and import tool. We can find it under Tools in our administration panel.

It is easy to use, we select to export all contents or select content depending on what we need.

This process will create an XML file which we will download. Head to the destination webpage and go to Tools => Import

Select the WordPress option, install and activate the plugin should it be necessary. Once we select the file with the new content, we will define an user as the author and if adjacent files are copied to our installation or if they are kept in the original web links. One additional click and the new content will be available in our WordPress.

This method does not allow to program to periodically export and import content or to have detailed control over custom entries. Let's look at other more complete options to export and import content in WordPress with full control of all settings.

Export content in WordPress through a plugin

De las muchas opciones disponibles, yo prefiero utilizar WP All Export. Este plugin permite seleccionar con todo detalle que elementos del contenido vamos a incluir y generar un archivo csv o xml con la información deseada. Veamos como funciona

Out of the many options available, I prefer to use WP All Export. This plugin allows to select with full detail which elements of the content we are to include and generate a .csv or .xml file with all the desired information. Let's look at how it works.

The first step is to select the content, for that we can configure a custom search or simply choos an element from the dropdown list. If we own the Pro version, we can turn on filters to refine our search.

By clicking on Customize Export we will head on to the next step where we willl decide what information will be exported. 

The procedure is simple. On the right side we've got the different elemetns which we will position into place inside the box. We have absolute control over the content and the structure of exported data.

Advanced Options allows us to, for example, choose the data splitter, if we have various languages we can choose one of the, and Exoprt Type allows us to define the format of the file with all exported data. Finally we can saves the settings for future use or loading an existing template.

We continue onto the third and final step.

If we own the Pro version, we can program the extraction of data. Thi is useful if, for example. we want to periodically send content to an external service.

Depending on our data, this export can take a lot of time. To avoid timeout errors, under advanced settings we can specify how many registries will be processed every instance. We can also give it a name to help locate this setting in the exports list to reuse it whenever necessary.

Check everything is in order, execute the process and download the generated file.

Managing exported content

Under Manage Export, we can find a list of completed exports, this way we won't need to follow every step again to repeat exports. We can also modify the configuration and delete those we do not need anymore.

WP All Export works perfectly fine with its default settings. Under Settings we can manage the templates we have created, manage the integration process with Zapier and have the possibility of coding our own functions in PHP, should it be necessary. 

Import content in WordPress through a plugin

To import content we will use WP All import. This plugin allows us to import content into our WordPress from any csv or xml files or from an Excel sheet. This process is very intuitive as we will see below.

The first step is to select the original data, once the file is loaded we select the content type in the destination. We choose between creating new content elements or updating the existing ones and then head to step 2.

In this step we can visualize the content and import it in case it is necessary and set filters if we would like to import part of the data. Once we are satisfied with the result we move on to step 3.

We establish the correct correspondance within the content elements to import and the entries. This is a completely intuitive process which will show us the proper settings depending on the type of content to import, for example importing images.

The final step is to establish the behavior to modify already existing data, and in advanced settings we can identify it with a descriptive name to locate it easily in the import list..

We click continue and wait to have our content available in our WordPress.

Similar to the exports, we will get a registry with the completed imports so as to repeat them with a single click. We can also save settings as a template for future usage. The latter is a very useful option, because depending on the structure of our entries, the set up can take a lot of time.

Export and import content through PHP

We have seen how to export and import content to our website using WP All Export and WP All Import. Although these are two complementary plugins, we can use them independently and in many cases they work well enough for the task.

WP All Import offers an API which allows theme and plugin developers to create add-ons to simplify the import process. In my case I have used WPML and Housez addons to transfer real estate properties from both sites

However, it's possible that we may have to go even further beyond in the customization process For example, the entry structures are different in both webs, which forces us to make modifications to them. We have various options:

Modifying the data files. Once downloaded, we can edit and make any adequate changes to it prior to the import process. This has to be done manually every time.

Add custom functions to the plugin. These options are available in some cases. However, to activate every function we need to purchase the Pro version.

Code our own process. If we need to make complex modifications, this may just be our only option. This is also a way to keep using the free version of the plugins.

Previous requirements

I like to use CSV as a transfer format, since it generates a smaller file and I find it easier to edit it, for this reason the minimum version of PHP is 5.3, although I do not consider this to be a problem nowadays. In my case I use fgetcsv() and anonymous functions. With the latter I avoid loading unused functions and reduce server resource consumption a little bit.

We can include our code directly into functions.php in our theme, although I prefer to store it in an independent file, for example, in a specific page. This way we can generate a visual interface according to our needs and have more control over the execution of the process.

Without getting into details, since each case needs its specific solution, I will show a fragment of code with the necessary elements to implement an import from a CSV file. We are supposing that the file contains three columns: title, content and attachment. And in order to not complicate the code, we implement a button in the notifications area to launch the process. .

View code

I tried to document the code as much as possible. You can ask any questions, however I hope this serves as a template to simplify the process of undergoing complex imports. The example, with a few modifications, has been taken from Sitepoint. 


We have seen many different methods of exporting and importing content in WordPress. Depending on the volume and complexity of the data we will use one or the other, but even if we need to code the entire process, WordPress gives us tools at our disposal which will greatly ease the task.

The fragment of code shown above can serve as a starting point for our own modifications. It can be downloaded here

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments