Importing data for advanced custom fields plugin?

I have a member section built using the http://www.advancedcustomfields.com plugin. There are 300 members that each have the following data:

  • Company name
  • Specialism (check boxes)
  • Web address
  • Telephone number
  • Region
  • Address
  • Email

What’s the best way to import into the database? How should I setup a csv file? I haven’t added the 300 member pages, I just have these custom fields setup using the plugin.

1
1

Sounds like you have successfully gotten all 300 Pages imported based on the comments. (Regardless of how you did it, either by using the WordPress import plugin or by using some MySQL tool like phpMyAdmin or Sequel Pro or whatever)… You have 300 pages in the wp_posts table. Let’s start from here then…

The ACF plugin uses the wp_postmeta table to populate and link custom fields to specific posts/pages. (A very thoughtful design, by the way)!

That table consists of 4 columns:

meta_id – A unique auto incremented primary key

post_id – A foreign key that links to the post or page

meta_key – In this case the name (key) of the custom field

meta_value – The actual text or content for that custom field

So if you’ve created a CSV file, you would basically create your data to fit into that model. If you have 300 records sitting in your wp_posts table, they should all have a unique ID (in the ID column). That’s the ID that you’ll put into the wp_postmeta.post_id column.

Now, if you inspect the Field Group you’ve created, you’ll see all of the Field Names (which are the wp_postmeta.meta_key values. Here’s a screenshot of an example in a project I’m working on right now:

ACF Example

I’ve named mine header_content and left_sidebar_content for example. Finally, throw the values of each of your fields into the wp_postmeta.meta_value field.

All of that is a high level walkthrough of the schema and structure of the data. The actual implementation of how you import the data is up to you. (Whether you use a CSV file, XML, or actually write some SQL to insert the data).

Hope that helps get you on the right track!

Leave a Comment