We will use the side value to display the meta box in the sidebar of the post edit page. The Post edit screen contexts that we will use here include normal, side, and advanced as the available context values. The $context parameter varies according to the admin screen. In our case, this is the recipe’s post edit area, so it will be the unique post type name which as mentioned before is recipes. The $screen attribute refers to the admin screen on which the meta box will be displayed. The callback function to show the box content will be display_vegan_meta_box. Here is the structure of the function with the arguments that we will use: add_meta_box( $id, $title, $callback, $screen, $context )įor the unique id we will use is_vegan and for the title of the meta box the string Is Vegan. To add a meta box in our custom post type we use the add_meta_box function provided by WordPress. In this tutorial we are going to expand on our custom post type by adding in a new meta box that will be used to define whether the recipe is vegan or not by ticking a checkbox. This tutorial follows on from our tutorial on Custom Post Types… if you want to follow along step-by-step then you’ll need to check out that article and create a custom post type called ‘recipes’ and then setup couple of ‘recipes’ test posts with a featured image selected. Now we’ve got a clearer idea of what exactly meta boxes are, we can move on and build our own custom meta box for our website. When you do this, you are actually updating the _thumbnail_id of that post’s metadata.Ĭreating a Meta Box for our Custom Post Type This is normally found in the right hand sidebar of a post’s admin screen. Depending on how the metadata is handled by the website, these boxes will appear in different locations on your screen.īy way of further example, let’s look at the Featured Image meta box. So, the main post editor, the containers for choosing categories, publishing the post, adding tags, adding a featured image are all meta boxes that contain HTML elements that interact with the post’s metadata. When you open a WordPress post to edit it you’ll see the page is broken up into different sections (many of which are located in the sidebar on the right hand side).Īll of these sections are technically ‘meta boxes’. You can find out more about custom fields by reading our article ‘ Getting Started with WordPress Custom Fields‘. Others can be added by a plugin or custom code and defined by the admin user. There are fields that are predefined by WordPress like the feature image which are technically custom fields. There are no limits on how many meta entries this table can have. Every key/value pair is considered a ‘post field’.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |