This document discusses how to use custom fields in WordPress for fun and profit. Custom fields allow storing key-value pairs of extra metadata alongside posts and pages. They are defined by a key and value, like "image: myphoto.jpg". The document provides examples of using custom fields to add images, contributor info, and e-commerce features to blog posts. Code samples demonstrate retrieving custom field values to display this extra information on websites.
1 of 9
More Related Content
Using Custom Fields For Fun And Profit
1. Using Custom Fields
For Fun and Profit
WordCamp Fraser Valley 2009
Dave Zille
2. Contact Info
Dave Zille
Email: dave@dazil.com
Twitter: @dazil
Skype: davezille
Web: http://www.dazil.com
Blog: http://www.dazil.com/blog
3. Outline
WordPress custom fields
What is a Custom Field?
How do I use them?
Usage examples
Fun
Add interesting info to your blog posts or pages
Add images/thumbnails to posts or pages
Profit
Add Shopping Cart to your WordPress site
4. WordPress Custom Fields
What is a custom field?
A little bit of information you can store alongside a
WordPress post or page
A custom field has two components
A key/value "pair"
Key is the name of the meta data element
eg. image
Value is the information itself
eg. "myphoto.jpg"
Examples:
Key: url Value: "http://www.mysite.net"
Key: my_mood Value: "Happy as a clam"
5. WordPress Custom Fields
Usage:
WordPress function
get_post_meta()
get_post_meta($post_id, $key,
$single)
Example:
get_post_meta($post->id, "my_mood",
true)
will return:
"Happy as a Clam"
Demo
6. Custom Field Usage Examples
Demo site: Comic Sightings
Adding contributor information to a post:
Custom field key: credit-name
Demo
see single.php (sample code)
7. Custom Field Usage Examples
Demo site: Comic Sightings
Adding photos to a post:
Custom field key: main-image
Demo
see product-demo.php (sample code)
8. Custom Field Usage Examples
Demo site: Comic Sightings
Adding a shopping cart
Custom field keys: price, product-name
Demo
see product-demo.php (sample code)