If you work with Genesis-powered themes, like I do, then you need to modify your strategy a bit for adding in a subtitle to a single post type. Let’s walk through it together as well as explore the Genesis codebase. Genesis builds the post’s title HTML structure in the lib/structure/post.php file in the function genesis_do_post_title(). This function is a registered callback to the event genesis_entry_header. Let’s look at this code and how it builds the post title’s HTML.
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.
Delete a Custom Field
In this episode, you and I will explore how to delete a custom field (post metadata) programmatically from the database. You’ll see how delete_post_meta() works and how you can target specific meta to delete.
Add a New Custom Field
Let’s add a new custom field, which is a post metadata, to the database. You’ll use add_post_meta() and walk through using it. You’ll see what it does in the database, how to use it, what the different arguments do, and even peak into WordPress Core. This function adds a new post metadata record WHEN: ‘unique’ is set to false (you can get duplicates with this one). ‘unique’ is set to true AND the meta value does not already exist in the database for that post ID. Huh? Watch the video and do it with me to better understand what this […]
Update an Existing Custom Field
Let’s update an existing custom field, which is a post metadata, in the database. You’ll use update_post_meta() and walk through using it. You’ll see what it does in the database, how to use it, what the different arguments do, and even peak into WordPress Core. This function does multiple tasks: If the post metadata exists, it updates the meta_value WHEN ‘unique’ is set to false. OR ‘unique’ is set to true and the existing meta_value matches what you pass in as the previous argument. If the post metadata doesn’t exist, then it adds it into the database. So this function […]
Get Subtitle Post Metadata
In this episode, you and I will add the subtitle to the Twenty Seventeen. Let’s walk through the strategy of: Finding where to add the new subtitle’s HTML in the theme. What HTML we will use. What functionality we need to get the subtitle out of the database and prepare it to render in the browser. Resources esc_html_e() get_post_meta() get_the_id()
The Database
Let’s explore the database in this episode. I’ll walk through how post metadata (custom fields) are related to their posts and where they live in the database. This episode is a basic overview. But to go deeper, you can do this lab:
Project: Add a Subtitle
In this lab, you and I are going to add a subtitle to the posts. How would you do that? Where would you start? Let’s start by giving the means for the site owner or author to input the subtitle in the WordPress Post Edit interface (in the back-end). There are 2 strategies here: Use the built-in interface that ships with WordPress Build a custom meta box In this lab, we’ll use the built-in interface. Why? I want you to focus on the database and WordPress functions that interact with the database. Then in the next lab, you’ll work on […]
What is a Meta Box?
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 […]
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