Wordpress : Register Post Type and Taxonomy


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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' );

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.