/wordpress-cpt-generator-class

A PHP class that helps in creating custom post types and their taxonomies.

Primary LanguagePHPGNU General Public License v3.0GPL-3.0

wordpress-cpt-generator-class

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

Quick Usage

  1. Include the library in your application
  2. 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,
	)
));
  1. 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,
	)
));
  1. If needed, assign your textdomain for translation.
$cpt->set_textdomain( 'text-domain' );

What Options are available?

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.