Notes from 11.25.14 Austin WordPress Intermediate Meetup
These presentation notes were developed to support those just learning how to create and display metadata in their WordPress sites. The Ins and Outs of WordPress Metadata describes how to go beyond pages and posts, and learn how to develop data entry screens for specific information whether it’s a shopping cart, a directory, recipes, genealogies or any other specialized content.
Nick Batik explained what metadata is and demonstrated custom content fields, and reviewed best plugins for creating and setting the field types such as check boxes, drop downs, radio buttons, text, and image fields. He demonstrated the underlying metadata code and ways to take it further. (See slide deck below.)
The second part of custom content is getting it to display on the public side of your website. As a site developer / designer you must add code to your theme to find and display the custom fields. Corey Ellis demonstrated custom loops and the Meta Data API, and how to retrieve and display the data entered in the backend of your site.
Note: When Nick or Corey use the phrase “post” throughout this presentation, they referring to a post of any post type, not the default blog post type bundled with WordPress.
What is metadata?
Metadata is set of data that describes and gives information about other data.
What is a post meta box?
A post meta box is a customizable box appearing on the post editing screen that allows an authorized user to select or enter information in addition to the main post content. This information is related to the post in some way.
What are Custom meta boxes?
Custom meta boxes are tools to enhance content. Meta boxes are the little blocks in the editor section for each post type. Meta boxes are commonly used by themes and plugins when a developer wants to implement a constantly formatted interface for saving/editing a number of custom fields than the one provided with WordPress.
What are WordPress Custom Fields?
Custom Fields are a form of meta-data that allows you to store arbitrary information with each Word- Press post. While this does not sound so powerful, it is the single most powerful component of WordPress posts and content types (aka post types). This meta-data is handled with key/value pairs. The key is a “name” which identifies the specific field thus it is a constant and should stay the same for all posts however you can use the same key multiple times within one post. The value is the information that will be displayed for the field when you call it in your WordPress theme thus it can change with each post.
How To Create Custom Post Meta Boxes In WordPress
The two most common types of data is entered into meta boxes are:
- Metadata (i.e. custom fields),
- Taxonomy terms.
Post metadata is data that’s saved in the wp_postmeta table in the database. Each entry is saved as four fields:
- meta_id: A unique ID for this specific metadata.
- post_id: The post ID this metadata is attached to.
- meta_key: A key used to identify the data (A single meta key can have multiple meta values.)
- meta_value: The value of the metadata.
Metadata is the key/value pairs saved for a specific post that let you to add custom data to your posts. It is particularly helpful when you’re developing custom post types.
How to use post metadata
To know how and when custom meta boxes are helpful with organizing content, you must understand how to add, update, delete, and get post metadata.
- add_post_meta(): Adds post metadata.
- update_post_meta(): Updates post metadata.
- delete_post_meta(): Deletes post metadata.
- get_post_meta(): Retrieves post metadata.
Below please find Nick Batik’s slide deck and other links and references.
- Understanding the Ins and Outs of WordPress Metadata
Austin WordPress Meetup
Tuesday, Nov. 25, 2014
Presenter: Nick Batik
- What is Meta Data?
Metadata is “data about data”.
There are two (metadata types):
• structural metadata, about the design and specification of data structures or “data about the containers of data”;
• and descriptive metadata about individual instances of application data or the data content.
Let’s Look at Some Examples (It will make more sense)
• Date of Publication
• Number of pages
- Business Directory
• Name of business
• Hours of operation
• Exposure time
• Focal length
• Pixel dimensions
• Where to get tickets
- Oh! So meta data is information about the book, business, photograph, and event!
Adding Metadata to WordPress
Custom Post Types The “container” for your metadata Example: • Books • Photo Portfolio • Business Directory • Events
Custom Fields The metadata for a Post Type Example: • Title • Author • Publisher • Date of Publication • Number of pages • ISBN
Custom Taxonomies Categories specific to a Post Type Example, a “genre” taxonomy for a book: • Science Fiction • Drama • Romance • Mystery • Western
Post Types can have multiple taxonomies
“Books” could also have a taxonomy of “binding”:
• hard cover
- …and “Publisher”:
• Prentice Hall
- Field Formats Choosing how each field should be edited
Text Field A single line of text
WYSIWYG Text Area
True/False Check for true, uncheck for false
Checkbox Select as many as you want
Radio Button Select only one from the list
File or Image
Embed content Such as videos, audio, slide shows, etc.
Link to other pages
Color or Date Pickers
WordPress Metadata Plugins
- Creating Custom Post Types
• Sections supported
• Roles & capabilities
• Menu position
33. Doing it with code
34. (code sample)
- Post Type Supports
Default: title and editor
• ‘editor’ (content)
• ‘author’ •
‘thumbnail’ (featured image, current theme must also support post-thumbnails)
• ‘comments’ (also will see comment count balloon on edit screen)
• ‘revisions’ (will store revisions)
• ‘page-attributes’ (menu order, hierarchical must be true to show Parent option)
• ‘post-formats’ add post formats, see Post Formats
- Post Type Menu Position
The position in the menu order the post type should appear. show_in_menu must be true.
Default: null – defaults to below Comments
• 5 – below Posts
• 10 – below Media
• 15 – below Links
• 20 – below Pages
• 25 – below comments
• 60 – below first separator
• 65 – below Plugins
• 70 – below Users
• 75 – below Tools
• 80 – below Settings
• 100 – below second separator
- Demo Creating a Custom Post Type with Types plugin
Demo Creating a Custom Post Type with PODS
Demo Adding Custom Fields to “Books” with Types
Demo Adding Custom Meta to Events with PODS, Types, and Advanced Custom Fields (ACF)
Demo A quick demo of how to do this in code…
Metadata Resources for designers and developers
Post Meta Data Section
Function Reference/add metadata
Other helpful links for WordPress Custom Content Fields
https://www.google.com/search?q=WordPress+Custom+Content+Fields&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-beta&channel=sb – rls=org.mozilla:en-US:official&channel=sb&q=WordPress+Custom+Content+Fields
Part 2: Displaying Your Metadata
Presenter: Corey Ellis