PostTypes v2.2
Simple WordPress custom post types.

Requirements

Installation

Install with composer

Run the following in your terminal to install PostTypes with Composer.
1
$ composer require jjgrainger/posttypes
Copied!
PostTypes uses PSR-4 autoloading and can be used with the Composer's autoloader. Below is a basic example of getting started, though your setup may be different depending on how you are using Composer.
1
require __DIR__ . '/vendor/autoload.php';
2
3
use PostTypes\PostType;
4
5
$books = new PostType( 'book' );
6
7
$books->register();
Copied!
See Composer's basic usage guide for details on working with Composer and autoloading.

Basic Usage

Below is a basic example of setting up a simple book post type with a genre taxonomy. For more information, check out the online documentation here.
1
// Require the Composer autoloader.
2
require __DIR__ . '/vendor/autoload.php';
3
4
// Import PostTypes.
5
use PostTypes\PostType;
6
use PostTypes\Taxonomy;
7
8
// Create a book post type.
9
$books = new PostType( 'book' );
10
11
// Attach the genre taxonomy (which is created below).
12
$books->taxonomy( 'genre' );
13
14
// Hide the date and author columns.
15
$books->columns()->hide( [ 'date', 'author' ] );
16
17
// Set the Books menu icon.
18
$books->icon( 'dashicons-book-alt' );
19
20
// Register the post type to WordPress.
21
$books->register();
22
23
// Create a genre taxonomy.
24
$genres = new Taxonomy( 'genre' );
25
26
// Set options for the taxonomy.
27
$genres->options( [
28
'hierarchical' => false,
29
] );
30
31
// Register the taxonomy to WordPress.
32
$genres->register();
Copied!

Notes

Author

Joe Grainger
Last modified 1d ago