Categories
Development

WordPress Custom Fields

Found the Custom Fields feature of WordPress to be very useful. I’m using them on the posts on this site that have ratings. It’s pretty cool. I’ve also used custom fields for one of my clients so that they can easily embed videos into their blogs.

Setting up a custom field is real easy. Within the WordPress admin near the bottom of a Write Post or Edit Post screen is an option for Custom Fields. You can select from existing field names the enter a value for that custom field or you can type a new custom field name into the key field to create a new custom field. So, creating custom fields is pretty easy, but how do you now present that info?

WordPress offers a get_post_meta() function to work with the custom fields. Below is an example in PHP of using the get_post_meta() to display the contents of a custom field named video.

echo get_post_meta($post->ID, "video", true);

Three parameters are being passed to get_post_meta. The first is the ID of the current post, then the name of the custom field, and last is if you want to return a single string or an array.

One reply on “WordPress Custom Fields”

Leave a Reply

Your email address will not be published. Required fields are marked *