Advertisement
Guest User

Metabox

a guest
Oct 24th, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. // Metabox Content
  2.  
  3. function meta_content()  
  4. {
  5.     $post = get_post_custom( $post->ID );
  6.     $selected = isset( $post['meta_options'] ) ? esc_attr( $post['meta_options'][0] ) : '';
  7. { ?>
  8.     <p>
  9.         <select name="meta_options" id="meta_options">
  10.             <option value="none" <?php selected( $selected, 'none' ); ?>>None</option>
  11.             <?php $options =& get_children( 'post_type=attachment&post_mime_type=audio' );
  12.                 foreach ( (array) $options as $attachment_id => $attachment ) { ?>
  13.             <option value="<?php echo $attachment_id; ?>" <?php selected( $selected, $attachment_id ); ?>><?php echo $attachment->post_title; ?></option>
  14.         <?php } ?>
  15.         </select>
  16.     </p>
  17. <?php }}
  18.  
  19. // Save Metabox Content
  20.  
  21. add_action( 'save_post', 'meta_save' );  
  22. function meta_save( $post_id )  
  23. {  
  24.     // Check for auto-save  
  25.     if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;  
  26.  
  27.         // Check for content
  28.         if( isset( $_POST['meta_options'] ) )
  29.             update_post_meta( $post_id, 'meta_options', esc_attr( $_POST['meta_options'] ) );
  30.     }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement