We use the WordPress nonce value to secure our saving process and determine if we should continue or not. Let’s talk about the nonce field and validation check in this episode. Watch this episode! We use the WordPress generated nonce for the following reasons: Validate if our meta box is on this screen. Validate that our meta box is (for the most part) valid. Nonce is a technique to validate that we are receiving what we expect. Resources WordPress Nonce wp_verify_nonce
A meta box provides an interface for site owners, author, editors, admins, etc. to view, add, delete, and edit custom fields (post metadata). In this hands-on coding lab, you will create a meta box boilerplate from scratch, one that you can use on any project.
WooHoo!! You did it! Great job! Let’s review what you learned in this lab: Custom field is the same thing as post metadata, metadata, and post meta. Custom field refers to the interface, such as a form. Post metadata refers to the code and database. You can use the built-in meta box to add, update, and delete custom fields in the back-end. WordPress provides functionality to get, update, add, and delete metadata programmatically in your theme or plugin.
Up to this episode, you have learned how to get, update, add, and delete post metadata. But WordPress provides additional functionality. Let’s explore these functions together: the_meta() get_post_custom() get_post_custom_values() get_post_custom_keys()
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.
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 […]
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 […]
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()
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:
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 […]