PHP code example of jjgrainger / wp-custom-post-type-class

1. Go to this page and download the library: Download jjgrainger/wp-custom-post-type-class library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jjgrainger / wp-custom-post-type-class example snippets




$books = new CPT('book');

$people = new CPT(array(
	'post_type_name' => 'person',
	'singular' => 'Person',
	'plural' => 'People',
	'slug' => 'people'
));

$books = new CPT('book', array(
	'supports' => array('title', 'editor', 'thumbnail', 'comments')
));

$blog = new CPT('post');

$books->register_taxonomy('genres');

$books->register_taxonomy(array(
	'taxonomy_name' => 'genre',
	'singular' => 'Genre',
	'plural' => 'Genres',
	'slug' => 'genre'
));

$books->filters(array('genre'));

$books->columns(array(
	'cb' => '<input type="checkbox" />',
	'title' => __('Title'),
	'genre' => __('Genres'),
	'price' => __('Price'),
	'rating' => __('Rating'),
	'date' => __('Date')
));

$books->populate_column('column_name', function($column, $post) {

	// your code goes here…

});

$books->populate_column('price', function($column, $post) {

	echo "£" . get_field('price'); // ACF get_field() function

});

$books->sortable(array(
	'column_name' => array('meta_key', true)
));

$books->sortable(array(
	'price' => array('price', true),
	'rating' => array('rating', true)
));

$books->menu_icon("dashicons-book-alt");

$books->set_textdomain('your-textdomain');

$books->flush();