0

I am writing an external program on c++ which supposed to import products to WordPress database (it should directly connect to remote MySQL server and just execute some SQL queries to create a new product). I have all the products' properties and remote database access, but I can't completely understand how does actually WordPress serves and orders all of it in it's database. Technology is too hard for me to understand by simply walking through the real working WP database, filled in with products :c. I also haven't found any documentations or schemes on internet.

There is only very useful db scheme of relationships between different WordPress tables, but it doesn't actually describe how is the information stored in inside.

I am new (from technical side) to that CMS, so, the final question is, which tables should be affected by my program to create a new product in WP database?

Relying upon your help.

3
  • Googling WordPress database schema got me this page -- Tour of the WordPress Database -- which looks like it might be more helpful than the image you found.
    – Pat J
    Commented Dec 8, 2016 at 17:35
  • I wouldn't write directly to the Database, that would be a harder program to write, and it also has other issues, e.g. none of the post save hooks will run, causing compatibility issues. Instead, why not make a nice JSON request to the REST api and create the product in WordPress? Now your C++ code just needs to json encode and fire off a remote request, a significantly simpler task. Ideally you would be writing it in PHP though, ideally a WP CLI command
    – Tom J Nowell
    Commented Dec 8, 2016 at 17:55
  • The count of products to import causes the main problem I am used to write the external program. It's about 30k+ products I need to import to database daily. Using api or internal plugins (such as WP All Import) forces apache to sleep 4ever and site is temporary unavailable for other clients during the import is running. Besides the performance loss, it's also takes very long time to proceed such a huge import to database.
    – impulsgraw
    Commented Dec 8, 2016 at 18:03

1 Answer 1

1

To add product, you need to add

  • an entry in posts table, with post_type='product', post_title='product_name', post_excerpt='product_description'. This will give you the post ID.
    • with the post ID, you will be able to add meta datas in the post_metas table._product_type, _visibility, _price, _sale_price....
    • use terms tables to add category related to the product

You can see all product metas (with get_post_meta() ) to learn more about all the needed one and their real names.

Ok, you want to do it with sql request, but you can also import products with a csv file or with the woocommerce Api, functions, class and dedicated method can make it easier to define the right sql request.

Hope it gives you some hints.

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.