Simple WordPress custom post types.
Run the following in your terminal to install PostTypes with Composer.
$ composer require jjgrainger/posttypes
PostTypes uses PSR-4 autoloading and can be used with Composers autoloader. Below is a basic example of getting started, though your setup may be different depending on how you are using Composer.
require __DIR__ . '/vendor/autoload.php';
use PostTypes\PostType;
$books = new PostType('book');
$books->register();
See Composer's basic usage guide for details on working with Composer and autoloading.
Below is a basic example of setting up a simple books PostType with a genre Taxonomy. For more information, check out the online documentation here.
// Require the Composer autoloader
require __DIR__ . '/vendor/autoload.php';
// Import PostTypes
use PostTypes\PostType;
// Create a books PostType
$books = new PostType('book');
// Attach the genre taxonomy, this is created below
$books->taxonomy('genre');
// Hide the date and author columns
$books->columns()->hide(['date', 'author']);
// Set the Books menu icon
$books->icon('dashicons-book-alt');
// Register the PostType to WordPress
$books->register();
// Create a genre Taxonomy
$genres = new Taxonomy('genre');
// Set options for the Taxonomy
$genres->options([
'hierarchical' => false,
]);
// Register the Taxonomy to WordPress
$genres->register();
- The full documentation can be found online at posttypes.jjgrainger.co.uk
- The class has no methods for making custom fields for post types, use Advanced Custom Fields
- The books example used in the README.md can be found in examples/books.php
- Licensed under the MIT License
- Maintained under the Semantic Versioning Guide
Joe Grainger