I have to achieve something on which I don't know how to approach it.

Base of the issue:

There's a bunch of data in another DB that I have to import into WP which so far wasn't possible due to them being multiple arrays that have to be repeated into fields(Advanced Custom Fields). As far as my research has gone I have not found an importer that supports them.

The problem:

Since I haven't found a solution and i'm not that far into developing WP(average maybe). The issue with WP (as far as I can compare with a self made CMS) is that it requires a certain format of the data that is inserted in the DB as it probably converts it when importing, thus you can't force plain data into it's DB. As well as i'll probably not be able to just do a query on which I do a query of for example SELECT * FROM ... to then show it on a plain page with a button that on click does INSERT INTO wp_postmeta.

The Questions

How can I achieve entering data from the secondary DB into the WP custom fields? As well as where do I even start researching how to do this? It probably is a core related thing and it also feels like I might need to create a plugin for this, please advice me as much as possible.

Instead of a table example i'll show an example of where the issue would commence: The issue

As you can see there are multiple fields with a button to add even more in the DB I have a data that is inserted in the same way for instance:

 Adress 1 Adress 2 Adress 3 Adress 4 Adress 5 Adress 6         

 Data 1   Data 2   Data 3   Data 4   Data 5   Data 6   

Thanks in advance!

  • Please post an example of multiple arrays containing table, so we can have look up and suggest.... Mar 10, 2014 at 13:18
  • Be aware that request for plugins recommendations are off topic.
    – s_ha_dum
    Mar 10, 2014 at 13:52
  • I deleted the plugin reccomendations question my bad.
    – David H
    Mar 10, 2014 at 14:11

2 Answers 2



... thus you can't force plain data into it's DB.

... is simply false. As is this...

As well as I'll probably not be able to just do a query on which I do a query of ...

The wpdb class, instantiated as the global $wpdb by the Core, can both insert and retrieve data with essentially pure SQL input. $wpdb->query() will run any query you like, while $wpdb->get_results, $wpdb->get_col, $wpdb->get_row, and $wpdb->get_var will retrieve data according to any SQL that you are capable of writing.

The question does arise as to whether you should run pure SQL, and generally when there is a Core function that can handle the case you should use it instead, but that is a bit of an aside.

If you need to access a completely different database you can instantiate a second wpdb object, just pass it the correct connection information.

And, WordPress is a PHP application. PHP works within WordPress just like it does outside of WordPress, that includes all of the database features. If you need to connect to an MSSQL or PostGreSQL database you should still be able to do so just like normal with PHP.

As far as inserting your data, what I would do is:

  1. Connect to the other database with a wpdb instance.
  2. Grab the data
  3. Look over the ACF code to work out how ACF inserts data
  4. And figure out which functions/methods are used
  5. Format the data accordingly
  6. And let ACF functions/methods insert data

I don't use ACF but I have browsed its code. It is a complicated animal. That research is well beyond anything I have time for in connection to this Q/A site.

  • The wpdb part I understand as I tested it(You helped me last time) and it successfully worked itself out. Also yes that is actually the question which I apologize for asking it in the wrong way. Though I don't understand your last statement about it being well beyond anything and having time for in connection? Also one more thing am I right saying there is nothing that can import repeated fields?
    – David H
    Mar 10, 2014 at 14:18
  • I don't know if anyone has written something to import ACF repeated fields, but that part of the question is off-topic anyway. I think that I have given you a reasonable outline for creating your own importer though.
    – s_ha_dum
    Mar 10, 2014 at 14:21
  • What exactly did you mean with "in connection to this Q/A site"? Also yes it did give me a way better insight of how to solve my problem. Is it allowed though to ask a question about plugins as a new question? Not sure if it qualifies for advertising or anything, i'd not want to do that.
    – David H
    Mar 10, 2014 at 14:27
  • @user3121076 : 1) I just mean that I don't have to time to research ACF and write code for a question like this. 2) Requests for plugin recommendations are explicitly off-topic. Questions highly dependent upon third party plugins and themes are usually closed as well.
    – s_ha_dum
    Mar 10, 2014 at 14:34
  • Of course I did not expect you to do so, I just need a push in the right direction. Also thank you very much for the answer, as well as i'll keep in mind not to make mistakes concerning third parties again.
    – David H
    Mar 10, 2014 at 14:40

Have you looked at WPDB , you can connect to other DB's and execute any queries .

$newdb = new wpdb($DB_USER, $DB_PASSWORD, $DB_NAME, $DB_HOST);
  • Yes I have but my issue is on bigger scale. I need to import an entire table into wordpress ACF repeater fields. What I thought was that I needed to INSERT data into the WP DB by going into the core and editing the standard WP importer since I haven't seen any importer yet that can do Repeater fields.
    – David H
    Mar 10, 2014 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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