Posts Tagged with: wpdb
Custom Database API – The Basic API Class
In the previous sections of this series, we have looked at reasons you should build a custom database API, we have discussed how to structure your data, and we have looked at how to create the database tables. Now it is time to build the basic API that we will use to actually interact with our database. This will involve writing an API class with all of the necessary methods for retrieving, inserting, updating, and deleting data.
Custom Database API – Creating the Tables
Custom Database API – Reasons for Custom Tables and an API
The WordPress database class and the other various APIs available make it pretty easy to interact with the WordPress database but often times you need to go a step further and create a custom API specific to your plugin’s database tables. Large plugins especially can benefit from having a custom database API as it standardizes common tasks, making them more reliable, more repeatable, and simpler to debug.
Sometimes direct $wpdb queries are better
WordPress has some really awesome functions and classes for retrieving data from the database: WP_Query, WP_User_Query, get_comments(), get_the_terms(), and many, many more. Most of the time these are the functions and classes you should use when querying data from the database–they have some great benefits, such as caching–but there are times when it is actually…
Retrieve Users Based on Meta Value
Just like the post meta system, WordPress has a powerful user meta system that allows developers to store additional “meta” information about the registered users in the database. This meta information can be just about anything you want it to be, and can serve a variety of purposes. At the time of writing this tutorial,…