Custom Post Types, Taxonomies or Meta?





@stompweb
Steven Jones

CUstom post types

  • Pages & Posts examples of built in post types

  • Incredibly flexible due to generic model
    • Nav menus
    • Attachments
    • Doughnuts

  • Post Statuses - publish, draft, private - add your own

  • Can be associated to terms & have meta data

Custom Post types


  • register_post_type() - you should always register a new post type using the function - do not use a plugin for this.

    • Creates a UI to add new posts of your post type (does not create anything in the database)

    • Creates a rewrite rule for your post type
      • e.g. http://www.yoursite.com/cars/

    • Allows you to use templates in your theme
      • archive -{post-type} .php
      • single-{post-type}.php

Taxonomies


  • Categories & Post Tags are examples of built in taxonomies.

  • Taxonomy != term
    • Taxonomy = Category
    • Term = Politics, Sports, Computing

  • Used to group posts in a meaningful way

  • Good to show faceted views using multiple terms across multiple taxonomies

Taxonomies

  • register_taxonomy() - you should always register taxonomies in your code, do not use a plugin - it is part of your site's structure!

  • Creates a UI to enter:
    • Term data
    • Associate a post with a term

  • Creates a rewrite rule for your taxonomy
    • http://www.yoursite.com/product-categories/cakes/

  • Allows you to use the following templates in your theme
    • taxonomy-{taxonomy}.php
    • taxonomy-{taxonomy-term}.php

post meta


  • Core usage of post meta is page template

  • Flexibility - almost unlimited - you can store just about anything you want to.

  • Used for additional data about a post. 

  • No UI/structure
    • Slow for querying
    • Bad for grouping

Example 1


Team Members on the about page

Example two


Ordering Pages

example 3


Properties on an estate agent website

Example 4


Types of trainers (e.g. running, football etc)

Example 5


Manufacturers of Cars (Audi, Ford etc)

What about Post to post relationships?

  • Could use meta but it's super slow

  • Does a post need to be a post? 

  • Posts 2 Post plugin 
    • Querying is quicker - separate database table
    • Two Way relationship
    • http://wordpress.org/plugins/posts-to-posts/

  • Shadow Taxonomies?
    • http://eamann.com/tech/wordpress-shadow-taxonomies/

Custom Post Types, Taxonomies or Meta?

By Steven Jones

Custom Post Types, Taxonomies or Meta?

WordPress North East - 20th March 2014

  • 2,621