What is best for storing user data for Wordpress

Context: I need to create a form with a lot of settings and quite a few fields (20+) for the site, and not install the plugin and modify the hell out of it (or by studying the plugin API), I decided to write my own plugin. Since I am doing this from scratch, the question of data storage should be answered.

Most people will suggest using a personalized message type and metadata rather than a user table, and while I am familiar with custom message types and taxonomies, etc. I wonder if this is better for pure data storage, which is equal to the log.

The form is one-time, and the data that I store will not be available at the front end of the site and will only be displayed in WP-admin, and this will most likely be the only page with a filtered table.

So the question is, does this require the use of a custom message type and metadata, or should I just create a table and use the $ wpdb class as this simplifies CRUD and still adheres to the "Wordpress way" to accomplish things.

Reading: This post makes a good example for a user table, especially since their example concerns the storage of personal data, efficiency and privacy issues. This question , which was answered several years ago, has the opposite opinion, but the precedent was different, since the stored data was for public display.

+6
source share
3 answers

I would suggest using a separate table. WP table postmeta is usually populated with a lot of information from many different plugins and often turns out to be the largest or largest table in the database. In addition, if you save it in the postmeta table, it will always be partially saved in the message table, as the two require each other so that the information is connected and completed. Therefore, if you exported / imported to another database, you would have to participate in a very unpleasant process, when user messages should be the same identifier as in the last database

In addition, the data is very easily accessible if it is in a separate table and should be easy to read even with phpmyadmin, and it is quite easy to encode a filtered table using the $ wpdb class if you have only basic sql knowledge.
All this comes from my recent experience of merging two large Wordpress sites in one and a lot of information stored as postmet ... I really want most of it to be stored in a user table, as this would make my life a lot easier.

The only reason for using a meta and personalized message type is that it is faster and easier (at least in my experience). Hope this helps, I'm really interested to know if there are any other opinions. Good luck with your project!

+4
source

Interest Ask!

I usually use (as you mentioned) custom post types and taxonomies for such cases. So that would be my path, the only thing I’m afraid of is where you mentioned "..many to the magazine ..."

I am sure that you will be better off using a separate table, it just sucks to work through the postmeta table. In the end, if you know how to use the $ wpdb class, you should be fine!

We are waiting for other users

+2
source

In most cases, it’s easy and simple to use a custom message type with metadata, because it runs quickly, and you can use all the cool Wordpress features for it.

The case when it is better to use a new table in the database is when you need to save a lot of data, i.e. access log or similar.

WooCommerce (a plugin from Wordpress users) saves products as CPT and all data that belongs as metadata.

+1
source

Source: https://habr.com/ru/post/1015062/


All Articles