48
Understanding the Ins and Outs of WordPress Metadata Austin WordPress Meetup Tuesday, Nov. 25, 2014 Presenter: Nick Batik @nick_batik http://HandsOnWP.com

Understanding the ins and outs of word press metadata

Embed Size (px)

Citation preview

Understanding the Ins and Outs of WordPress

Metadata

Austin WordPress MeetupTuesday, Nov. 25, 2014

Presenter: Nick Batik

@nick_batikhttp://HandsOnWP.com

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.

Huh?

Let’s Look at Some Examples(It will make more sense)

Books• Title

• Author

• Publisher

• Date of Publication

• Number of pages

• ISBN

Business Directory• Name of business

• Description

• Address

• Phone

• Owner

• Hours of operation

Photography• Resolution

• Exposure time

• F-stop

• Focal length

• Aperture

• Pixel dimensions

Event

• Location

• Date

• Performers

• Description

• Where to get tickets

Oh!

So meta data is information about the book, business, photograph, and event!

Adding Metadata to WordPress

Custom Post TypesThe “container” for your metadata

Example:

• Books

• Photo Portfolio

• Business Directory

• Events

Custom FieldsThe metadata for a Post Type

Example:

• Title

• Author

• Publisher

• Date of Publication

• Number of pages

• ISBN

Custom TaxonomiesCategories 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

• paperback

…and “Publisher”:

• Addison-Wesley

• Wiley

• Prentice Hall

• Bantam

Field FormatsChoosing how each field should be edited

Text FieldA single line of text

Text Area

WYSIWYG Text Area

True/FalseCheck for true, uncheck for false

CheckboxSelect as many as you want

Radio ButtonSelect only one from the list

Drop-down List

File or Image

Embed content

Such as videos, audio, slide shows, etc.

Link to other pages

Color or Date Pickers

WordPress Metadata Plugins

• Advanced Custom Fieldshttps://wordpress.org/plugins/advanced-custom-fields/

• Types - Custom Fields and Custom Post Types Managementhttps://wordpress.org/plugins/types/

• Pods - Custom Content Types and Fieldshttps://wordpress.org/plugins/pods/

Creating Custom Post Types

• Labels

• Icons

• Visibility

• Sections supported

• Roles & capabilities

• Menu position

Demo

Doing it with code

add_action( 'init', 'codex_book_init' );

/**

* Register a book post type.

*

* @link http://codex.wordpress.org/Function_Reference/register_post_type

*/

function codex_book_init() {

$labels = array(

'name' => 'Books',

'singular_name' =>’Book',

'menu_name' =>'Books',

'name_admin_bar' => 'Book',

'add_new' => 'Add New',

'add_new_item' => 'Add New Book',

'new_item' => 'New Book',

'edit_item' => 'Edit Book',

'view_item' => 'View Book',

'all_items' => 'All Books',

'search_items' ‘Search Books',

'parent_item_colon' => 'Parent Books:',

'not_found' => 'No books found.',

'not_found_in_trash' => No books found in Trash.'

);

$args = array(

'labels' => $labels,

'public' => true,

'publicly_queryable' => true,

'show_ui' => true,

'show_in_menu' => true,

'query_var' => true,

'rewrite' => array( 'slug' => 'book' ),

'capability_type' => 'post',

'has_archive' => true,

'hierarchical' => false,

'menu_position' => null,

'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )

);

register_post_type( 'book', $args );

}

$args = array(

'labels' => $labels,

'public' => true,

'publicly_queryable' => true,

'show_ui' => true,

'show_in_menu' => true,

'query_var' => true,

'rewrite' => array( 'slug' => 'book' ),

'capability_type' => 'post',

'has_archive' => true,

'hierarchical' => false,

'menu_position' => null,

'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )

);

register_post_type( 'book', $args );

}

Post Type SupportsDefault: title and editor

• 'title'

• 'editor' (content)

• 'author'

• 'thumbnail' (featured image, current theme must also support post-thumbnails)

• 'excerpt'

• 'trackbacks'

• 'custom-fields'

• '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

DemoCreating a Custom Post Type with Types plugin

DemoCreating a Custom Post Type with PODS

DemoAdding Custom Fields to “Books” with Types

DemoAdding Custom Meta to Events with PODS, Types,

and Advanced Custom Fields (ACF)

DemoA quick demo of how to do this in code…