Upload
nicholas-batik
View
242
Download
3
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
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.
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
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
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