A PHP class that helps in creating custom post types and their taxonomies. Simply include the library in your theme or plugin, initiate a new class to BNE_CPT
- Include the library in your application
- Setup the Custom Post Type (basic usage). For example, let's register a custom post type for books.
$cpt = new BNE_CPT( 'my_books_cpt_slug', array(
'singular' => __( 'Book', 'bne-testimonials' ),
'plural' => __( 'Books', 'bne-testimonials' ),
'slug' => 'books',
'args' => array(
'labels' => array(
'menu_name' => __( 'Books', 'text-domain' ),
),
'supports' => array( 'title', 'editor', 'thumbnail' ),
'menu_icon' => 'dashicons-book-alt',
'show_ui' => true,
'show_in_menu' => true,
)
));
- Setup a custom Taxomony (basic usage). Going with our Books post type, we'll register a taxonomy for Genres.
$cpt->register_taxonomy( 'my_books_taxonomy_slug', array(
'singular' => __( 'Genre', 'text-domain' ),
'plural' => __( 'Genres', 'text-domain' ),
'slug' => 'categories',
'args' => array(
'labels' => array(
'menu_name' => __( 'Genres', 'text-domain' ),
),
'show_admin_column' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_admin_column' => true,
)
));
- If needed, assign your textdomain for translation.
$cpt->set_textdomain( 'text-domain' );
All of the arguments used for register_post_type
and register_taxonomy
can be set. Any options omitted in the above examples will use their default settings defined by WordPress.