Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jjgrainger/posttypes
Simple WordPress custom post types.
https://github.com/jjgrainger/posttypes
post-type posttype taxonomies wordpress wp
Last synced: 6 days ago
JSON representation
Simple WordPress custom post types.
- Host: GitHub
- URL: https://github.com/jjgrainger/posttypes
- Owner: jjgrainger
- License: mit
- Created: 2016-08-16T12:45:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-12-11T19:18:29.000Z (about 1 month ago)
- Last Synced: 2025-01-02T14:04:51.826Z (20 days ago)
- Topics: post-type, posttype, taxonomies, wordpress, wp
- Language: PHP
- Homepage: https://posttypes.jjgrainger.co.uk/
- Size: 206 KB
- Stars: 372
- Watchers: 21
- Forks: 48
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# PostTypes v2.2.1
[![tests](https://github.com/jjgrainger/PostTypes/actions/workflows/tests.yml/badge.svg)](https://github.com/jjgrainger/PostTypes/actions/workflows/tests.yml) [![codecov](https://codecov.io/gh/jjgrainger/PostTypes/branch/master/graph/badge.svg?token=SGrK2xDF46)](https://codecov.io/gh/jjgrainger/PostTypes) [![Latest Stable Version](https://flat.badgen.net/github/release/jjgrainger/PostTypes/stable)](https://packagist.org/packages/jjgrainger/posttypes) [![Total Downloads](https://flat.badgen.net/packagist/dt/jjgrainger/PostTypes)](https://packagist.org/packages/jjgrainger/posttypes) [![License](https://flat.badgen.net/github/license/jjgrainger/PostTypes)](https://packagist.org/packages/jjgrainger/posttypes)
> Simple WordPress custom post types.
## Requirements
* PHP >=7.2
* [Composer](https://getcomposer.org/)
* [WordPress](https://wordpress.org) >=5.1## Installation
#### Install with composer
Run the following in your terminal to install PostTypes with [Composer](https://getcomposer.org/).
```
$ composer require jjgrainger/posttypes
```PostTypes uses [PSR-4](https://www.php-fig.org/psr/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.
```php
require __DIR__ . '/vendor/autoload.php';use PostTypes\PostType;
$books = new PostType( 'book' );
$books->register();
```See Composer's [basic usage](https://getcomposer.org/doc/01-basic-usage.md#autoloading) 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](https://posttypes.jjgrainger.co.uk).
```php
// 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
* The full documentation can be found online at [posttypes.jjgrainger.co.uk](https://posttypes.jjgrainger.co.uk)
* The class has no methods for making custom fields for post types, use [Advanced Custom Fields](https://advancedcustomfields.com)
* The book's example used in the README.md can be found in [examples/books.php](examples/books.php)
* Licensed under the [MIT License](https://github.com/jjgrainger/PostTypes/blob/master/LICENSE)
* Maintained under the [Semantic Versioning Guide](https://semver.org)## Author
**Joe Grainger**
* [https://jjgrainger.co.uk](https://jjgrainger.co.uk)
* [https://twitter.com/jjgrainger](https://twitter.com/jjgrainger)