Hi I am currently using wordpress 4.0 multisite(bitnami multisite stack) and am using WPMU directory plugin to create business reviews directory.

Have some custom fields created using custompress which is included with the WPMU directory plugin. I need to import over 3 million businesses data that is on my local mysql installation.

Have tried to use WP ultimate csv importer (free) where it is importing all the custom fields within the custom post (created by directory plugin) but is not correctly importing the listing_tag(post_tag) and listing_category(post_category). Whereas the other csv importers do not have an option of importing custom fields.

Have some basic knowledge of mysql so if it takes for me to create the various tables using my local mysql installation and importing the data directory into the wordpress mysql database i am fine to do it.

But can someone point me to create a query to generate the same and understand how to going about this.

  • If I understand you correctly, you have a records already in a non-WordPress database that you want to import into custom fields in WordPress. Is that correct? Commented Nov 9, 2014 at 15:59
  • @SeamusLeahy if i can find an alternative way to import the data i am fine that as well. Or i would like to do that with custom fields for custom posts
    – rajesh
    Commented Nov 9, 2014 at 16:19

1 Answer 1


I've run into this issue before when needing to import a large dataset into WordPress. The importers start failing. What I suggest is creating a custom PHP script that reads the values from the non-WP database and then inserts them into WordPress using the WordPress functions. This way, we ensure all the background data processing happens in WordPress.

The first thing is to setup the script. We are going to run the script from the command line because it will not run into the timeout restraints that you normally get when PHP runs on a webpage.

In your WordPress root directory, create a new file import-data.php:

// Include WordPress functions
define('WP_USE_THEMES', false);

echo "It Works\n";

From the command line, go to your WordPress directory and run: php import-data.php. You should see It Works printed out.

From here, I can only give you general help with the rest of the process as I don't know the schematic of your data.

Now you'll want to do you own MySQL query to your non-WP database

// Include WordPress functions
define('WP_USE_THEMES', false);

// Do you MySQL database connection and query here
$original_data = array(/* ... placeholder */);

Assuming each record will be a post with custom field data. You'll need to first create the post object which has the basic fields such as title and content. It also has the fields that you'll want to manually set such as post_type if you are using a custom post_type or the post_status to publish it by default.

After you create the post object, you'll get the post ID which you'll need to insert the custom fields.

foreach ($original_data as $data) {
   // Useful to see where we are in the import process
  echo "Inserting record ", $data['id'], "\n";

  // First create the new post object
  // See: http://codex.wordpress.org/Function_Reference/wp_insert_post
  $post_data = array( 'post_title' => $data['name'], 'post_type' => 'product', 'post_status' => 'publish' );
  $post_id = wp_insert_post( $post_data );

  // Insert custom post data
  // See: http://codex.wordpress.org/Function_Reference/add_post_meta
  add_post_meta($post_id, 'price', $data['Price']);
  add_post_meta($post_id, 'quantity', $data['q']);

  // What if you also want taxonomy terms?
  // See: http://codex.wordpress.org/Function_Reference/wp_set_post_terms
  wp_set_post_terms( $post_id, array($data['style']), 'styles' );
echo "Finished\n";

Hopefully this helps you figure out how to import your data.

  • Hi around 50 fields including the default WP and custom fields created. The mysql query that i have generates an output for these 50 fields. please let me know if this works?
    – rajesh
    Commented Nov 10, 2014 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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