WordPress register custom post type code


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



Copy this code and paste it in your HTML
  1. // Register Custom Post Type
  2. // snippet updated 6/3/2011
  3.  
  4. // Bare Bones
  5. // -- from Ian Stewart at bit.ly/wppoweredby
  6. function powered_by_create_post_type() {
  7. register_post_type( 'foo', array(
  8. 'public' => true,
  9. ) );
  10. }
  11. add_action( 'init', 'powered_by_create_post_type' );
  12.  
  13. // Basic and Quick
  14. // -- from Konstantin Kovshenin at bit.ly/kovcpt
  15. // -- also see Justin Tadlock at bit.ly/jtadcpt
  16. // -- and Custom Post Type Generator at bit.ly/generate-wpcpt
  17.  
  18. // Fire this during init
  19. register_post_type('foo', array(
  20. 'label' => __('Foos'),
  21. 'singular_label' => __('Foo'),
  22. 'public' => true,
  23. 'show_ui' => true,
  24. 'capability_type' => 'post',
  25. 'hierarchical' => false,
  26. 'rewrite' => false,
  27. 'query_var' => false,
  28. 'supports' => array('title', 'editor', 'author', 'excerpt', 'custom-fields')
  29. ));
  30.  
  31. // Full and Comprehensive
  32. // -- generated with the Custom Post Type Generator at bit.ly/generate-wpcpt
  33.  
  34. add_action( 'init', 'register_cpt_foo' );
  35. function register_cpt_foo() {
  36. $labels = array(
  37. 'name' => _x( 'Foos', 'foo' ),
  38. 'singular_name' => _x( 'foo', 'foo' ),
  39. 'add_new' => _x( 'Add New', 'foo' ),
  40. 'add_new_item' => _x( 'Add New foo', 'foo' ),
  41. 'edit_item' => _x( 'Edit foo', 'foo' ),
  42. 'new_item' => _x( 'New foo', 'foo' ),
  43. 'view_item' => _x( 'View foo', 'foo' ),
  44. 'search_items' => _x( 'Search Foos', 'foo' ),
  45. 'not_found' => _x( 'No foos found', 'foo' ),
  46. 'not_found_in_trash' => _x( 'No foos found in Trash', 'foo' ),
  47. 'parent_item_colon' => _x( 'Parent foo:', 'foo' ),
  48. 'menu_name' => _x( 'Foos', 'foo' ),
  49. );
  50. $args = array(
  51. 'labels' => $labels,
  52. 'hierarchical' => true,
  53. 'description' => 'These are foos.',
  54. 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'custom-fields' ),
  55. 'taxonomies' => array( 'category' ),
  56. 'public' => true,
  57. 'show_ui' => true,
  58. 'show_in_menu' => true,
  59. 'show_in_nav_menus' => true,
  60. 'publicly_queryable' => true,
  61. 'exclude_from_search' => false,
  62. 'has_archive' => true,
  63. 'query_var' => true,
  64. 'can_export' => true,
  65. 'rewrite' => true,
  66. 'capability_type' => 'post'
  67. );
  68. register_post_type( 'foo', $args );
  69. }
  70. // end

URL: http://bit.ly/kovcpt

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.