PHP code example of hanamura / wp-post-type

1. Go to this page and download the library: Download hanamura/wp-post-type 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/ */

    

hanamura / wp-post-type example snippets




// extend PostType class and create your own post type
class MyPostType extends \WPPostType\PostType
{
	function __construct()
	{
		// set post type name: 'my-post-type'
		// - archive page: yoursite.com/my-post-type
		// - single page: yoursite.com/my-post-type/post-slug
		parent::__construct('my-post-type', array(
			// second argument of `register_post_type()`
			// see: http://codex.wordpress.org/Function_Reference/register_post_type
			'supports' => array('title', 'editor'),
			'has_archive' => true
		));
	}

	// compose edit screen
	public function onAddMetaBoxes()
	{
		// create 'Info' box
		add_meta_box(
			'my-post-type-info',
			'Info',
			array($this, 'addMetaInfo'),
			$this->name
		);
	}

	public function addMetaInfo($post)
	{
		// input tags for custom fields: 'nickname' and 'birth_year'