Skip to content

Instantly share code, notes, and snippets.

@aderaaij
Created February 13, 2014 11:49
Show Gist options
  • Save aderaaij/8973764 to your computer and use it in GitHub Desktop.
Save aderaaij/8973764 to your computer and use it in GitHub Desktop.
Create Custom post types for WordPress
<?php
/* = New custom post-type
-------------------------------------------------------------- */
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'events',
array(
'labels' => array(
'name' => __( 'Events' ),
'singular_name' => __( 'Events' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'author','tag','custom-fields', 'thumbnail' ),
'rewrite' => array( 'slug' => 'events', 'with_front' => false ),
'taxonomies' => array('post_tag'),
)
);
register_post_type( 'shop',
array(
'labels' => array(
'name' => __( 'Shop' ),
'singular_name' => __( 'Shop' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'author','tag','custom-fields', 'thumbnail' ),
'rewrite' => array( 'slug' => 'shop', 'with_front' => true ),
'taxonomies' => array('post_tag'),
)
);
}
/* = Create conditional post-type tags
-------------------------------------------------------------- */
function is_post_type($type){
global $wp_query;
if($type == get_post_type($wp_query->post->ID)) return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment