juvo / posttypes
Simple WordPress custom post types.
dev-master
2023-03-05 19:21 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.7
- phpunit/phpunit: 9.*
- squizlabs/php_codesniffer: 3.*
- szepeviktor/phpstan-wordpress: ^1.1
This package is auto-updated.
Last update: 2024-10-15 04:53:04 UTC
README
Simple WordPress custom post types library based on the work of Joe Grainger
Requirements
Installation
Install with composer
Run the following in your terminal to install PostTypes with Composer.
$ composer require juvo/posttypes
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.
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.
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.
// 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' ); // Add custom capabilities $books->capabilities([], ['editor', 'author']); // 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
- 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 book's example used in the README.md can be found in examples/books.php
- Licensed under the MIT License
- Maintained under the Semantic Versioning Guide
Original Author
Joe Grainger