Posted By

xavsio4 on 06/16/11


Tagged

wordpress posts custom


Versions (?)

Add a metabox to multiple posts


 / Published in: PHP
 

URL: http://www.deluxeblogtips.com/2010/05/howto-meta-box-wordpress.html

This function will loop all the registered post types, and for each post type create a meta box with given data. Here links is assimilated to post types

  1. $meta_box = array(
  2. 'id' => 'my-meta-box-1',
  3. 'title' => 'Custom meta box 1',
  4. 'pages' => array('post', 'page', 'link'), // multiple post types, accept custom post types
  5. 'context' => 'normal',
  6. 'priority' => 'high',
  7. 'fields' => array(
  8. 'name' => 'Text box',
  9. 'desc' => 'Enter something here',
  10. 'id' => $prefix . 'text',
  11. 'type' => 'text',
  12. 'std' => 'Default value 1'
  13. )
  14. )
  15. );
  16.  
  17. / Add meta box
  18. function mytheme_add_box() {
  19. global $meta_box;
  20.  
  21. foreach ($meta_box['pages'] as $page) {
  22. add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box', $page, $meta_box['context'], $meta_box['priority']);
  23. }
  24. }

Report this snippet  

You need to login to post a comment.