Return to Snippet

Revision: 42254
at March 2, 2011 07:15 by crypticsoft


Initial Code
// custom post types
function create_post_type() {
	register_post_type( 
	'mysite_listings',
		array(
			'labels' => array(
				'name' => __( 'Listings' ),
				'singular_name' => __( 'Listing' )
			),
		'public' => true,
        'menu_position' => 5,
        'rewrite' => array('slug' => 'lookup'),
        'support' => array('title','author','editor','thumbnail','comments')
		)
	);
}	

add_action( 'init', 'create_post_type' );

// taxonomies
function listing_taxonomy() {
   register_taxonomy(
	'usa_states',
    'mysite_listings',
    array(
        'hierarchical' => true,
        'label' => 'US States',
        'query_var' => true,
        'rewrite' => array('slug' => 'usa')
    )
);

}
//
add_action( 'init', 'listing_taxonomy' );

Initial URL
http://codex.wordpress.org/Post_Types

Initial Description
Example shows how to  register post types for : 
* Listings (defined as 'mysite_listings' with the rewrite slug 'lookup')
* Then registers the 'usa_states' taxonomy to the mysite_listings post type.

Initial Title
Wordpress : Register Post Type and Taxonomy

Initial Tags
post, wordpress

Initial Language
PHP