Quantcast
Channel: Custom Post Meta – Build Your Own Business Website
Viewing all articles
Browse latest Browse all 10

Lesson 17 – Part 1 – What is Custom Post Meta?

$
0
0

Good morning everybody and welcome to this live class on Lesson 17 of the Customize Thesis Like a Pro tutorial series. Today, what we’ll be doing is learning how to create a new custom post meta in the Thesis theme. Specifically, what we’ll be doing is learning how to use custom post meta to create user-selectable elements on a given post or page so that the user can choose custom template or custom layout or custom sidebar configuration or custom menu configuration as well as a handful of other things.

Custom post meta is a very powerful tool that allows you to associate information with a post that’s not actually post content and you can use that information to control how that post or page displays, that’s what we’ll be working on here today. We’ll open the file we were working on previously and what we’re going to do here now is start adding some custom post meta.

Custom Post Meta Explained

Custom post meta is information that is associated with a post or a page or other WordPress elements. It’s information that’s associated with it but it’s not directly the main information. For example, in a post, common post meta is something like the Thesis post image. If we come over here and just edit this page for a moment, the Thesis theme has a whole bunch of post meta that it creates, this SEO Details and Additional Style, that is custom post meta.

The Meta Keywords, the Robots Meta Tag, the CSS Class, Post Image and Thumbnail, all those are custom post meta. It’s not the content of the post obviously, it’s just important information that is associated with the post thus making it meta. There’s other kinds of meta data in WordPress. For example there’s User Meta and there is Taxonomy Meta. An example of taxonomy meta can be seen under Categories.

Taxonomy Meta Created by the Thesis Theme

The Thesis theme has created some taxonomy meta as well and that looks like the title tag, the meta description, keywords, robots meta tags, introductory headline and introductory content. These are all pieces of meta associated with the taxonomy categories. Then there’s user meta and it can be things like your twitter url, it can have some kinds of contact information, you can add lots of different kinds of meta associated with the user. That’s what meta, it’s information and is associated with the specific WordPress element.

In this case, we’re talking about post meta so information that’s associated with a specific post, page or custom post type. We call it post meta but in this context, all content types are posts so custom meta applies to all post types including custom post types.

Custom Fields

Now, there is an interface that’s built into WordPress for saving custom meta and that’s called custom fields. If you want to see your custom fields, open up screen options and check this custom fields box, scroll down here and you can see this custom fields thing here. You can actually create your own custom fields so you could click on this button that says, custom field. I want to add a new custom field so my new custom field might be Rick Field then maybe it’s my name Rick Anderson. If I add custom field, now there’s a piece of custom post meta called ‘Rick Field’ and that’s its value and that custom post meta is associated with this post but not with any other post.

Create Custom Meta Box

There’s also custom meta boxes and that’s what we’re really talking about today so that’s Multimedia Box Options. In the Thesis theme, it is a custom meta box with custom meta data or custom fields in this custom fields term so you have two mechanisms for creating custom post meta. One of them is using this manual method of custom fields and the other one is creating a meta box. Traditionally, creating a meta box has been complicated so people haven’t done it. That’s something that we’re going to get over here today.

Post Meta Data

Post meta data is stored in the post meta table so here’s the Lesson 17 database. In this database, you see there’s this table called wp_postmeta and that’s where all the post meta is stored. Each piece of post meta has 4 parts. It has a meta_id which is just a sequential number that follows each time you add a new piece of post meta regardless of where it is, it gets the next number for it’s meta_id.

There’s the post_id which is the ID of the custom post type, post or page that the meta is associated with. There is the meta_key which is essentially the name of the custom post meta so for example, that one that I just created there was ‘Rick Field’, that was the name of this meta_key then the meta_value which is the name that’s inside the value.

If we look at say, your meta_id 62, it’s associated with post_id 30 and the meta_key is Thesis Post Image and the value of that key is this image that I’m using which is essentially the URL of that image. This is an example of custom post meta and how the custom post meta is stored. What we’ll be doing when we retrieve custom post meta is we’ll be retrieving it for a given post_id with the given field name and the given value.


Viewing all articles
Browse latest Browse all 10

Trending Articles