PHP code example of aurooba / cpt

1. Go to this page and download the library: Download aurooba/cpt 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/ */

    

aurooba / cpt example snippets






// Yep feel free to use spaces in your name
$custom_post_type = new Aurooba\CPT( 'custom post type' );

$custom_post_type = new Aurooba\CPT(
	'singular name', // singular taxonomy name, human readable
	$args, // an array of custom parameters for the custom post type
	$labels // an array of custom labels for the custom post type
);

$custom_post_type->add_taxonomy(
	'Taxonomy', // singular taxonomy name
	// array of custom parameters for the taxonomy
	array(
		'hierarchical' => false,
	),
	$labels, // array of custom labels for the taxonomy
)

/**
 * Initialize a Resource Custom Post Type
 * @return void
 */
function initialize_cpts() {

	$resource = new Aurooba\CPT( 'resource');

}

add_action( 'after_setup_theme', 'initialize_cpts' );

/**
 * Initialize a Resource Custom Post Type
 * @return void
 */
function initialize_cpts_and_taxonomies() {

	// initialize cpt
	$resource = new Aurooba\CPT( 'resource' );

	// add Resource Type taxonomy
	$resource->add_taxonomy( 'Resource Type' );

}

add_action( 'after_setup_theme', 'initialize_cpts_and_taxonomies' );

$resource = new Aurooba\CPT(
		'resource',
		array( 'menu_icon' => 'dashicons-share-alt' ),
	);


// Your icon SVG Code. Alternatively, you can pass the path to an SVG file.
$resource_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="#ffffff" d="M608 0H160c-17.67 0-32 13.13-32 29.33V112h48V48h48v64h48V48h224v304h112c17.67 0 32-13.13 32-29.33V29.33C640 13.13 625.67 0 608 0zm-16 304h-48v-56h48zm0-104h-48v-48h48zm0-96h-48V48h48zM128 320a32 32 0 1 0-32-32 32 32 0 0 0 32 32zm288-160H32a32 32 0 0 0-32 32v288a32 32 0 0 0 32 32h384a32 32 0 0 0 32-32V192a32 32 0 0 0-32-32zm-16 240L299.31 299.31a16 16 0 0 0-22.62 0L176 400l-36.69-36.69a16 16 0 0 0-22.62 0L48 432V208h352z"/></svg>';

$resource = new Aurooba\CPT(
		'resource',
		array(
			'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode( $resource_icon ) ),
	);

/**
 * Initialize a Resource Custom Post Type
 * @return void
 */
function initialize_cpts() {

	// create a block template to e', 'textdomain' ),
			),
		),
		array(
			'core/paragraph',
			array(
				'content' => __( 'Places where this resource can be helpful are:>', 'textdomain' ),
			),
		),
	);

	$resource = new Aurooba\CPT(
		'resource',
		array(
			'menu_position' => 26,
			'menu_icon'     => 'dashicons-plus-alt',
			'template'      => $block_template,
			'rewrite'       => true,
			'capability_type' => 'resource',
			'map_meta_cap' => true,
			'supports'      => array(
				'title',
				'editor',
				'thumbnail',
				'author',
				'custom-fields',
			),
		),
	);

}

add_action( 'after_setup_theme', 'initialize_cpts' );


	$resource->add_taxonomy(
		'Resource Type',
		array(
			'capabilities' => array(
				'manage_terms' => 'manage_resource_type',
				'edit_terms'   => 'edit_resource_type',
				'delete_terms' => 'delete_resource_type',
				'assign_terms' => 'assign_resource_type',
			),
		),
	);


$resource->add_taxonomy( 'Post Tag' );
$resource->add_taxonomy( 'Category' );