Post Type
The main goal of Cuztom is to register Custom Post Types. This can easily be done with the Cuztom_Post_Type class.
$book = new Cuztom_Post_Type( $name, $args, $labels );
$name
(string|array) The name/title of the Post Type. When using an array, the first element is the name, the second element is the plural name.
$args
(array) Arguments used for the Post Type. Take a look here to see which arguments are available
$labels
(array) If you don't set the labels yourself, Cuztom will do it for you. To see which labels can be used, take a look here
Arguments
has_archive
Normally has_archive defaults to false, with Cuztom it defaults to true.
Methods
Post Type support
You can add/remove post type support by using a method, handy when you want to add/remove it conditionally. Here is a list of all features.
// Add support
$book->add_post_type_support( $feature );
// Remove support
$book->remove_post_type_support( $feature );
// Check for support
$book->post_type_supports( $feature );
Add Meta Box
You can use an object method to easily attach a Meta Box to the new Post Type. See Post (Meta Box) for the complete documentation.
$book->add_meta_box( $id, $title, $data, $context, $priority );
Add Taxonomy
Like Meta Boxes, you can also attach (existing) Taxonomies to the Post Type object. See Taxonomy for the complete documentation.
$book->add_taxonomy( $name );
Examples
Set a plural name
The first parameter is the title (and name) of the Post Type. Cuztom will determine the plural form of the title. If you want to set it yourself, you can do so like this:
// Automatic plural
$book = new Cuztom_Post_Type('Book');
// Set a custom plural
$book = new Cuztom_Post_Type( array( 'Book', 'Books' ) );
Arguments
You can pass various arguments to Post Type object. Here is the full list.
$book = new Cuztom_Post_Type( 'Book', array(
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'exclude_from_search' => true
) );
Updated over 8 years ago