As WordPress developers, we often need a way to store and retrieve data. The most common reason for that is that we need to store and retrieve settings for our plugin or theme. But the reality is that there are countless of other reasons why you’d need to store and retrieve data. So how do we do it? Well, the primary tool that we have at our disposal to do this is the options API. It’s an API that offers a way for us to store and retrieve data from the WordPress database. It’s pretty much as indispensable as the plugin API. We often can’t build anything in WordPress without it. That’s why it’s worth looking a bit deeper at how it works. At its core, the options API is an API that lets us interact with the wp_options database table. With it, we can add, remove and update values stored in the database table. The database table itself has four columns: option_id, option_name, option_value and autoload. option_id is the primary key of the wp_options table. It autoincrements each time that MySQL adds a new row to the table. But, in practice, WordPress doesn’t use it for anything. The two important columns of the wp_options table are the option_name
Share This