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:
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!
This…
… is simply false. As is this…
The
wpdb
class, instantiated as theglobal
$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:
wpdb
instance.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.
Have you looked at WPDB , you can connect to other DB’s and execute any queries .