Introduction
One of WordPress’ greatest features is its ability for customization. There are many sites out there that could benefit greatly from these features. I’ve seen sites that sell cars and houses to simple music sites that could benefit from one specific customization function within WordPress, the register_post_type. The register_post_type function, as its name suggests allow the user (or theme) to add a new post type such as car, house or album. Once this post type has been registered, the user can then start adding functionality to WordPress that is unique to the post type. Using a custom post type opens up the use of custom taxonomies and more
Adding a custom post type
For this example I’m going to stick with the Car sales example. To add our post type we can define several labels that are used to populate menus and various options throughout the site. We also have to define some basic characteristics of our post type that we want WordPress to know about and handle for us. These include if we want to have an archive listing or if the post supports certain features such as excerpts.
register_post_type( 'car', array( 'labels' => array( 'name' => __( 'Cars' ), 'singular_name' => __( 'Car' ), 'add_new' => 'Add Car', 'add_new_item' => 'Add Car', 'edit' => 'Edit Cars', 'edit_item' => 'Edit Car', 'new-item' => 'New Car', 'view' => 'View Car', 'view_item' => 'View Car', 'search_items' => 'Search Cars', 'not_found' => 'No Cars Found', 'not_found_in_trash' => 'No Cars Found in Trash', 'parent' => 'Parent Car' ), 'description' => 'Car Post Type', 'public' => true, 'has_archive' => true, 'show_ui' => true, 'capability_type' => 'page', 'rewrite' => array( 'slug' => 'car', 'with_front' => false ), 'supports' => array('title', 'editor', 'thumbnail', 'author', 'page-attributes') ) );A quick overview of a car tells us that there are certain characteristic that can be assigned to cars. Simple examples are:
Number of doors Body type, e.g. Saloon, hatchback, estate or 4×4 Color Fuel Type, e.g. Diesel or Petrol Engine size
These attributes or characteristics could the custom taxonomies we will be assigning to our custom post type. An example taxonomy would be the number of doors. It would look something like this:
register_taxonomy('car_doors', 'car',...