Custom Post Type in Wordpress


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



Copy this code and paste it in your HTML
  1. add_action('init', 'press_post_type');
  2.  
  3. function press_post_type() {
  4.  
  5. //step 1: create custom post type
  6. $labels = array(
  7. 'name' => _x('Press', 'Press'),
  8. 'singular_name' => _x('Press', 'Press'),
  9. 'add_new' => _x('Add New', 'Press'),
  10. 'add_new_item' => __('Add New Press'),
  11. 'edit_item' => __('Edit Press'),
  12. 'new_item' => __('New Press'),
  13. 'all_items' => __('All Press'),
  14. 'view_item' => __('View Press'),
  15. 'search_items' => __('Search Press'),
  16. 'not_found' => __('No Press found'),
  17. 'not_found_in_trash' => __('No Press found in Trash'),
  18. 'parent_item_colon' => '',
  19. 'menu_name' => 'Press'
  20. );
  21.  
  22. $args = array(
  23. 'labels' => $labels,
  24. 'public' => true,
  25. 'publicly_queryable' => true,
  26. 'show_ui' => true,
  27. 'show_in_menu' => true,
  28. 'query_var' => true,
  29. 'rewrite' => true,
  30. 'capability_type' => 'post',
  31. 'has_archive' => true,
  32. 'hierarchical' => false,
  33. 'menu_position' => null,
  34. 'supports' => array( 'title', 'editor', 'author', 'thumbnail' )
  35. );
  36.  
  37. register_post_type('press',$args);
  38.  
  39. add_action("admin_init", "press_meta");
  40.  
  41. function press_meta(){
  42. add_meta_box("press_info_meta", "Press", "press_meta_data", "press", "side", "low");
  43. }
  44.  
  45. function press_meta_data() {
  46. global $post;
  47. $custom = get_post_custom($post->ID);
  48. $link = $custom["link"][0];
  49. ?>
  50. <p><label>link:</label>
  51. <input type="text" name="link" value="<?php echo $link; ?>" /></p>
  52.  
  53. <?php
  54. }
  55.  
  56. add_action('save_post', 'save_press');
  57.  
  58. function save_press(){
  59. global $post;
  60. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
  61. return $post->ID;
  62. }
  63.  
  64. update_post_meta($post->ID, "link", $_POST["link"]);
  65. }
  66.  
  67. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.