You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While the default WordPress database schema is perfect for most content-related data types, there may be instances where you need to create custom tables in a WordPress database. One example of this is when a plugin has a specific use case that extends beyond what the custom post-type functionality of WordPress offers. In this tutorial, you will learn how to create and manage custom WordPress database tables, how to interact with these tables, and some maintenance considerations.
Related Resources
Links to related content on Learn, HelpHub, DevHub, GitHub Gutenberg Issues, DevNotes, etc.
You might consider making the title more specific - such as Custom Database tables - so that it is not confused with html tables, the table block in site content or selecting a table-specific plugin. Or direct it toward developers rather than users.
I thoroughly enjoyed your tutorial and here is what I noted during the video:
You clearly and concisely met all objectives in this video including Where to find information about creating custom database tables, How to create custom database tables, and How to interact with these custom database tables.
Your example code and the resources mentioned in the video were very helpful in understanding the process of creating custom database tables. I was easily able to follow along with your explanations and points
At the end of the video, you quickly reviewed table updates. I appreciate that you mentioned this process.
Great tutorial and I wouldn't change a thing about it other than the two items you mentioned above.
Yes, this information is important and should be included in the tutorial. It is essential to emphasize to the user that when creating custom tables in WordPress, it is crucial to version them to control and update the table structure if necessary. Additionally, it is important to note that this technique allows for updates to be applied consistently without compromising the integrity of the stored data in the table. Therefore, versioning is a valuable and indispensable resource for managing custom tables in WordPress.
As I mentioned to another reviewer in an earlier comment I do think that a follow-up tutorial on custom tables would be good here:
So I do want to dive more into custom tables in the future, including something about how one might manage the actual upgrade routine, what to do if queries fail, etc.
The problem exists in balancing the limitation of creating a tutorial video 5-10 minutes long, keeping the content engaging and easier to follow for viewers, without trying to rush through all the available information about a specific topic.
Quite honestly, the topic of custom tables could be a series of tutorials, even a short course on the subject.
So I just want to make sure I understand your specific review feedback here, as I think there are two action items:
explain to the user that certain practices were used only to illustrate a concept, but are not recommended.
add details on table versioning
Would you agree that a follow-up tutorial (or tutorials) including things like versioning, what to do if queries fail, and other topics related to custom tables would make sense?
Additionally, if you're interested, this might be content you or another contributor might be interested in working on.
I'm wondering now if this item, as well as the items about when to create tables and when to delete them, should be in the follow-up tutorial.
What I'm thinking is:
This tutorial = the basics of creating, inserting data, updating, and deleting custom tables (aka the theory)
Follow-up tutorial = how you would actually implement this with real-world examples (aka in practice)
Adding tables on plugin activation and removing them only on uninstall
Using the table exists check on inserts and updates. Thinking about this more, running a table exists check every time you insert or update data isn't super performant, maybe an option stored once the table is created is better, although this doesn't solve the problem if the table is deleted some other way. That being said...
Implementing proper checks for all queries, with error output to the user if any of them fail. This would prevent the problem at 2) because then at least it can fail gracefully and report an error.
When, and how, to use prepare with query for a custom insert or delete (although I can't think of a real-world example at this time)
How to implement the upgrade routine, to manage table updates
This would be similar to another two-part series I did recently on plugin vulns:
I'm thinking of this in terms not only of being able to create courses based on this content, where one small step follows the next, but also in terms of the learning pathways project.
@jonathanbossenger that sounds like a good approach to me. It would be very easy to overwhelm the user with all of the nuances in a single tutorial and splitting them out mitigates that and allows you to spend more time on each.
Activity
SierraTR commentedon Sep 19, 2023
You might consider making the title more specific - such as Custom Database tables - so that it is not confused with html tables, the table block in site content or selecting a table-specific plugin. Or direct it toward developers rather than users.
[-]Tutorial - Custom Tables[/-][+]Tutorial - Custom Database Tables[/+]jonathanbossenger commentedon Sep 20, 2023
That's a good point @SierraTR, edited.
jonathanbossenger commentedon Sep 26, 2023
WIP Script - https://github.com/jonathanbossenger/wp-content/blob/main/tutorials/fundamentals-02-custom-tables.md
jonathanbossenger commentedon Sep 26, 2023
WIP video for review:
Custom.Database.Tables.mp4
In preparing this video for review, I realized there are two fixes I need to make
IDfield should beidplugin installnotplugin uninstallI will make sure to fix those before the video is published.
TinaCollier commentedon Sep 26, 2023
Hello @jonathanbossenger ,
I thoroughly enjoyed your tutorial and here is what I noted during the video:
Great tutorial and I wouldn't change a thing about it other than the two items you mentioned above.
digitalchild commentedon Sep 27, 2023
Great tutorial @jonathanbossenger my only question is why did the custom table docs not get migrated from codex?
13 remaining items
jonathanbossenger commentedon Oct 3, 2023
Thanks for your review @Zebedeu
I'm just checking, do you feel that this needs to be added, or that this idea is already covered in the tutorial?
Zebedeu commentedon Oct 3, 2023
Yes, this information is important and should be included in the tutorial. It is essential to emphasize to the user that when creating custom tables in WordPress, it is crucial to version them to control and update the table structure if necessary. Additionally, it is important to note that this technique allows for updates to be applied consistently without compromising the integrity of the stored data in the table. Therefore, versioning is a valuable and indispensable resource for managing custom tables in WordPress.
jonathanbossenger commentedon Oct 3, 2023
@Zebedeu thanks for your feedback.
As I mentioned to another reviewer in an earlier comment I do think that a follow-up tutorial on custom tables would be good here:
The problem exists in balancing the limitation of creating a tutorial video 5-10 minutes long, keeping the content engaging and easier to follow for viewers, without trying to rush through all the available information about a specific topic.
Quite honestly, the topic of custom tables could be a series of tutorials, even a short course on the subject.
So I just want to make sure I understand your specific review feedback here, as I think there are two action items:
Would you agree that a follow-up tutorial (or tutorials) including things like versioning, what to do if queries fail, and other topics related to custom tables would make sense?
Additionally, if you're interested, this might be content you or another contributor might be interested in working on.
jonathanbossenger commentedon Oct 3, 2023
@ryanwelcher for the "if table exists check" on inserting data, would you be happy with using
get_varand aSHOW TABLESMySQL statement?$table_existswould either be the table name, orNULLif it doesn't exist.ryanwelcher commentedon Oct 3, 2023
Explaining the why here is probably more important than the implementation but that looks great to me and demonstrates the steps perfectly.
jonathanbossenger commentedon Oct 3, 2023
Thanks @ryanwelcher.
I'm wondering now if this item, as well as the items about when to create tables and when to delete them, should be in the follow-up tutorial.
What I'm thinking is:
This tutorial = the basics of creating, inserting data, updating, and deleting custom tables (aka the theory)
Follow-up tutorial = how you would actually implement this with real-world examples (aka in practice)
preparewithqueryfor a custom insert or delete (although I can't think of a real-world example at this time)This would be similar to another two-part series I did recently on plugin vulns:
I'm thinking of this in terms not only of being able to create courses based on this content, where one small step follows the next, but also in terms of the learning pathways project.
Thoughts?
ryanwelcher commentedon Oct 5, 2023
@jonathanbossenger that sounds like a good approach to me. It would be very easy to overwhelm the user with all of the nuances in a single tutorial and splitting them out mitigates that and allows you to spend more time on each.
jonathanbossenger commentedon Oct 5, 2023
Thank you @ryanwelcher I appreciate your experienced feedback on this topic.
jonathanbossenger commentedon Oct 13, 2023
https://learn.wordpress.org/tutorial/custom-database-tables/
Update hacktoberfest-2023.md
Update hacktoberfest-2023.md (#1939)