PHP code example of pelmered / post-types-creator

1. Go to this page and download the library: Download pelmered/post-types-creator 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/ */

    

pelmered / post-types-creator example snippets


$options = array(
  // Use ACF for storing meta data
  'use_acf' => true
);

$ptc = new \PE\Post_Types_Creator();
$text_domain = 'text-domain';
        
$ptc->set_post_types(array(
    'stores' => array(
        'singular_label' => _x('store', 'Post type singular', $text_domain),
        'plural_label'  => _x('stores', 'Post type plural', $text_domain)
    )
));

add_action( 'init', array($ptc, 'init'), 0 );

$ptc = new \PE\Post_Types_Creator();
$text_domain = 'text-domain';
        
$ptc->set_post_types(array(
    'stores' => array(
        'singular_label' => _x('store', 'Post type singular', $text_domain),
        'plural_label'  => _x('stores', 'Post type plural', $text_domain),
        'description'   => _x('All company stores', 'Post type description', $text_domain),
        
        // Make post type drag and drop sortable in admin list view (default: false)
        'sortable'      => true,
        'taxonomy_filters' => true,
        'admin_columns' => array(
            'image' => array(
                //Column header/label
                'label' => 'Image',
                //In what position should the column be (optional)
                'location'  => 2,
                //callback for column content. Arguments: $post_id
                'cb'    => 'example_get_featured_image_column' 
            )
        )
        
        // Override any defaults from register_post_type()
        // http://codex.wordpress.org/Function_Reference/register_post_type
        'supports'            => array( 'title', 'editor', 'thumbnail',),
        'taxonomies'          => array( 'area' ),
    )
));

add_action( 'init', array($ptc, 'init'), 0 );

function example_get_featured_image_column( $post_id )
{
    echo get_the_post_thumbnail( $post_id, 'thumbnail' );
}

$ptc = new \PE\Post_Types_Creator();
$text_domain = 'text-domain';

$ptc->set_taxonomies(array(
    'area' => array(
        'singular_label' => _x('area', 'Post type singular', $text_domain),
        'plural_label'  => _x('areas', 'Post type plural', $text_domain),
        'description'   => _x('Areas for grouping stores', 'Post type description', $text_domain),
        'post_type'    => 'stores',
        
        // Make post type drag and drop sortable in admin list view (default: false). Affects all get_terms()-queries
        'sortable'      => true,
        
        // Override any defaults from register_taxonomy()
        // http://codex.wordpress.org/Function_Reference/register_taxonomy
        
    )
));

add_action( 'init', array($ptc, 'init'), 0 );

$ptc->set_taxonomies(array(
    'product_cat' => array(
        'register'      => false,
        'post_type'     => array( 'product' ),
        'sortable'      => true,
    ),
));

add_filter( 'pe_ptc_post_type_labels', 
	function( $generated_args, $post_type_slug, $post_type_args ) {
		
		// do what you want with $generated_args
		//And then return it back to the plugin
		return $generated_args;
	}, 
10, 3)

$post_type['singular_label_ucf'] = ucfirst($post_type['singular_label']);
$post_type['plural_label_ucf'] = ucfirst($post_type['plural_label']);

$generated_args = array(
    'label'               => __( $post_slug, $this->text_domain ),
    'description'         => __( $post_type['plural_label_ucf'], $this->text_domain ),
    'labels'              => array(
        'name'                  => _x( $post_type['plural_label_ucf'], 'Post Type General Name', $this->text_domain ),
        'singular_name'         => _x( $post_type['singular_label_ucf'], 'Post Type Singular Name', $this->text_domain ),
        'menu_name'             => __( $post_type['plural_label_ucf'], $this->text_domain ),
        'parent'                => sprintf(__( 'Parent %s', $this->text_domain ), $post_type['singular_label']),
        //'parent_item_colon'     => sprintf(__( 'Parent %s:', $this->text_domain ), $post_type['singular_label']),
        'all_items'             => sprintf(__( 'All %s', $this->text_domain ), $post_type['plural_label']),
        'view'                  => sprintf(__( 'View %s', $this->text_domain ), $post_type['singular_label']),
        'view_item'             => sprintf(__( 'View %s', $this->text_domain ), $post_type['singular_label']),
        'add_new'               => sprintf(__( 'Add %s', $this->text_domain ), $post_type['singular_label']),
        'add_new_item'          => sprintf(__( 'Add new %s', $this->text_domain ), $post_type['singular_label']),
        'edit'                  => __( 'Edit', $this->text_domain ),
        'edit_item'             => sprintf(__( 'Edit %s', $this->text_domain ), $post_type['singular_label']),
        'update_item'           => sprintf(__( 'Update %s', $this->text_domain ), $post_type['singular_label']),
        'search_items'          => sprintf( __('Search %s', $this->text_domain), $post_type['plural_label']),
        'not_found'             => sprintf(__( 'No %s found', $this->text_domain ), $post_type['plural_label']),
        'not_found_in_trash'    => sprintf(__( 'No %s found in trash', $this->text_domain ), $post_type['plural_label']),
    ),
);