How To Create Custom Post Type

Create the ff. class, replace the class name and the private variable values and call it.

class CustomPostTypeJobs
{
private $postTypeName = 'Jobs';
private $postTypeNameSingular = 'Jobs';
private $supports = array( 'title', 'editor', 'thumbnail', 'categories');
public function __construct($options = array())
{
if (!is_array($options['supports'])) {
$options['supports'] = array();
}
$this->supports = $options['supports'] + $this->supports;
add_action('init', array($this, 'createPostType'));
}
public function createPostType() {
register_post_type( 'jobs',
array(
'labels' => array(
'name' => $this->postTypeName,
'singular_name' => $this->postTypeNameSingular
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => strtolower($this->postTypeName)),
'supports' => $this->supports,
)
);
}
}

 

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPrint this pageEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *