If I want to save settings for my plugin then it is pretty easy and straight forward.

Now I would like to save to the database a bit more.

A file name, and 3 other values that only apply to that file. And there are many files with those values. Is it possible to save kind of subarrays using built in database methods? How can I delete and sort them etc?

5 s
5

I rarely disagree with otherwise knowledgeable users, but in this case I can’t help it. In my opinion calling the usage of non-core database tables bad practice per se is just simply wrong.

The choice of whether to go with core tables or add your own depends on several factors.

A query’s execution time depends on the size of the table. Hence, if you’re planning on storing significant amounts of data, a separate table catering to just this one type of specific data set will inevitably be the more efficient solution.

If you store a lot of regular posts or CPTs alongside these specific data sets, wp_posts as well as wp_postmeta can grow quickly.

For me, this choice ultimately depends on how “posty” the data is. Should it support an author, comments, revisions, excerpts or the like? If so, I’ll go with CPTs and/or core functionality. If not, I’ll go with separate tables for the sake of resource usage and efficiency.

If Eugene’s notion were correct, none of the existing well-written plugins would add their own tables, which fortunately is not the case.

Leave a Reply

Your email address will not be published. Required fields are marked *