What is a Meta Box in WordPress? It’s an interface to interact with metadata. Bam, that’s it. In the back-end, WordPress has built-in meta boxes for categories, publishing, tags, and the featured image. You can build a custom one which has the HTML form fields to provide an interface to work with the custom fields (metadata). For example, this is the meta box I built for the episode configuration: What do you notice? It has a checkbox, select dropdown, and text input fields. Bingo, it’s a form with form fields. Remember what I taught you previously. Custom fields are these […]
Labs
Labs are hands-on coding projects that you build along with Tonya as she explains the code, concepts, and thought processes behind it. You can use the labs to further your code knowledge or to use right in your projects. Each lab ties into the Docx to ensure you have the information you need.
Each lab is designed to further your understanding and mastery of code. You learn more about how to think about its construction, quality, maintainability, programmatic and logical thought, and problem-solving. While you may be building a specific thing, Tonya presents the why of it to make it adaptable far beyond that specific implementation, thereby giving you the means to make it your own, in any context.
What is a Custom Field?
We need a solid definition of what a custom field is. But we also need to know what it is, how we can use it, and why. Per WordPress codex, a custom field is: WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as meta-data. It goes on to say that they are key/value pairs. That’s important as we use the key to get access to the value. Per WP Beginner, a custom field is: Custom fields, also referred to as post meta, is a feature in WordPress […]
Lab Introduction
Let’s introduce you to this lab and what you will be doing. Then starting at 1:16, you’ll setup your sandbox website to be ready to do the lab with me. This will include: launching Local by Flywheel creating a new local website environment adding 2 posts into your new sandbox, using Lorem Ipsum for the dummy content Installing PHP Kint using one of these 2 plugins: 4:13: UpDevTools as a must-use plugin 8:29: PHP Kint Debugger plugin that’s in the WordPress plugin repository
SQL to Update Custom Field
Up until now, you’ve been getting data out of the database. It’s time to update data in the database. You’ll learn about how to update custom fields in the wp_postmeta database table both by writing the native SQL and using update function from WordPress Core. First, let’s write the SQL to change the custom field’s value in the database. You’ll learn about the UPDATE keyword in SQL. Then let’s update the subtitle using update_post_meta(). When you run the following code, the subtitle changes and then renders out to the browser. You’ll look at the SQL queries WordPress generates via the […]
SQL to Get a Custom Field
Let’s talk about post metadata. WordPress stores metadata for post’s content into its wp_postmeta database table. When you need a piece of metadata that does not already exists, then you create a new custom field. Therefore, a custom field is nothing more than a post metadata that you specify. That’s it. Hint: You’ll learn how WordPress optimizes SQL queries to speed up your webpage loading. In this episode, you’ll look at the sequence of the SQL queries that WordPress does when loading a page: grabs the post, then terms, and then all of the post metadata. The metadata is then […]