PostTypes
  • PostTypes v2.2.1
  • Getting Started
  • PostTypes
    • Create a Post Type
    • Add Taxonomies
    • Filters
    • Columns
    • Menu Icons
    • Flush Rewrite Rules
  • Taxonomies
    • Create a Taxonomy
    • Add to Post Type
    • Columns
  • Notes
  • Contributing
  • Changelog
Powered by GitBook
On this page
  • Requirements
  • Installation
  • Basic Usage
  • Notes
  • Author

PostTypes v2.2.1

NextGetting Started

Last updated 7 months ago

Simple WordPress custom post types.

Requirements

  • PHP >=7.2

  • >=5.1

Installation

Install with composer

Run the following in your terminal to install PostTypes with .

$ composer require jjgrainger/posttypes

PostTypes uses 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.

require __DIR__ . '/vendor/autoload.php';

use PostTypes\PostType;

$books = new PostType( 'book' );

$books->register();

Basic Usage

// Require the Composer autoloader.
require __DIR__ . '/vendor/autoload.php';

// Import PostTypes.
use PostTypes\PostType;
use PostTypes\Taxonomy;

// Create a book post type.
$books = new PostType( 'book' );

// Attach the genre taxonomy (which 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 post type 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();

Notes

Author

Joe Grainger

See Composer's guide for details on working with Composer and autoloading.

Below is a basic example of setting up a simple book post type with a genre taxonomy. For more information, check out the .

The full documentation can be found online at

The class has no methods for making custom fields for post types, use

The book's example used in the README.md can be found in

Licensed under the

Maintained under the

basic usage
online documentation here
posttypes.jjgrainger.co.uk
Advanced Custom Fields
examples/books.php
MIT License
Semantic Versioning Guide
https://jjgrainger.co.uk
https://twitter.com/jjgrainger
Composer
WordPress
Composer
PSR-4