WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For my custom post type i needed to add the Attribute Meta box, but i wanted to add an extra field to it.

So here i have copied the Page Attribute meta box code and added my select options, but i need help rewriting the 'Module Type' select box so it functions properly when saving the page.

 function page_attributes_meta_box2($post) {
      $post_type_object = get_post_type_object($post->post_type);
       if ( $post_type_object->hierarchical ) {
           $pages = wp_dropdown_pages(array('post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0));
           if ( ! empty($pages) ) {
  <p><strong><?php _e('Parent') ?></strong></p>
   <label class="screen-reader-text" for="parent_id"><?php _e('Parent') ?></label>
   <?php echo $pages; ?>
           } // end empty pages check
       } // end hierarchical check.
   <p><strong><?php _e('Order') ?></strong></p>
   <p><label class="screen-reader-text" for="menu_order"><?php _e('Order') ?></label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order) ?>" /></p>
   <p><?php if ( 'page' == $post->post_type ) _e( 'Need help? Use the Help tab in the upper right of your screen.' ); ?></p>

   <p><strong><?php _e('Module Type') ?></strong></p>
   <label class="screen-reader-text" for="_cnote_module_page_type"><?php _e('Module Type') ?></label>
   <select id="_cnote_module_page_type" name="_cnote_module_page_type">
        <option value="default">Default</option>
        <option value="parent">Parent</option>
        <option value="chat">Chat</option>

function add_post_template_metaboxr() {
    add_meta_box('postparentdiv', __('Post Template'), 'page_attributes_meta_box2', 'module', 'side', 'high');

**note that i have not renamed everything yet, theres a lot of copy and pasting in here

share|improve this question
up vote 0 down vote accepted

To save post meta fields from custom meta boxes you need to hook into save_post with something like this:

add_action( 'save_post', 'myplugin_save_postdata' );

There is some full example code on adding meta boxes on the codex Function Reference/add meta box

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.