Posted By

crypticsoft on 03/02/11


Tagged

post wordpress type taxonomy


Versions (?)

Wordpress : Register Post Type and Taxonomy


 / Published in: PHP
 

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

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

  1. // custom post types
  2. function create_post_type() {
  3. register_post_type(
  4. 'mysite_listings',
  5. 'labels' => array(
  6. 'name' => __( 'Listings' ),
  7. 'singular_name' => __( 'Listing' )
  8. ),
  9. 'public' => true,
  10. 'menu_position' => 5,
  11. 'rewrite' => array('slug' => 'lookup'),
  12. 'support' => array('title','author','editor','thumbnail','comments')
  13. )
  14. );
  15. }
  16.  
  17. add_action( 'init', 'create_post_type' );
  18.  
  19. // taxonomies
  20. function listing_taxonomy() {
  21. register_taxonomy(
  22. 'usa_states',
  23. 'mysite_listings',
  24. 'hierarchical' => true,
  25. 'label' => 'US States',
  26. 'query_var' => true,
  27. 'rewrite' => array('slug' => 'usa')
  28. )
  29. );
  30.  
  31. }
  32. //
  33. add_action( 'init', 'listing_taxonomy' );

Report this snippet  

You need to login to post a comment.