Posted By

tomdowning on 09/21/11


Tagged

wordpress


Versions (?)

WP meta boxes


 / Published in: PHP
 

add custom meta boxes to post types

  1. //DISPLAY META BOXES
  2. add_action("admin_init", "admin_init");
  3. function admin_init(){
  4. global $pagenow, $typenow;
  5. if (empty($typenow) && !empty($_GET['post'])) {
  6. $post = get_post($_GET['post']);
  7. $typenow = $post->post_type;
  8. }
  9.  
  10.  
  11. add_meta_box("function_name", "box title", "function_name", 'post_type', "normal", "high");
  12. }
  13.  
  14. function function_name() {
  15. global $post; ?>
  16. <p>Label:</p><textarea cols="80" rows="3" name="meta_name"><? echo get_post_meta($post->ID, 'meta_name', true); ?></textarea>
  17. <?
  18. }
  19.  
  20.  
  21.  
  22. //SAVING META BOXES
  23. add_action('save_post', 'save_details');
  24. function save_details() {
  25. global $post;
  26.  
  27. if(isset($_POST['meta_name'])) {
  28. update_post_meta($post->ID, "meta_name", $_POST['meta_name']);
  29. }
  30. }

Report this snippet  

You need to login to post a comment.