Advertisement
Guest User

add_post_meta One Key with Multiple Values

a guest
Dec 29th, 2011
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Your Plugin Name Here
  4. Plugin URI: http://your-site.com
  5. Description: Your description here.
  6. Version: 1.0
  7. Author: Your Name
  8. Author URI: ttp://your-site.com
  9. License: A "Slug" license name e.g. GPL2
  10. */
  11.  
  12. add_action('save_post','ez_portfolio_gallery_save');
  13. add_action( 'add_meta_boxes', 'ez_portfolio_gallery_box' );
  14.  
  15. function ez_portfolio_gallery_save($post_ID){
  16.    
  17.     global $post;
  18.     $ez_portfolio_gallery = $_POST['ez_portfolio_gallery'];
  19.  
  20.     //verify post is not a revision
  21.     if ( !wp_is_post_revision( $post_ID ) ) {
  22.        
  23.         add_post_meta($post_ID, 'ez_portfolio_gallery', $ez_portfolio_gallery);
  24.        
  25.     }
  26. }
  27.  
  28.  
  29. function ez_portfolio_gallery_box(){
  30.     add_meta_box( 'ez_portfolio_gallery_box', 'Portfolio Gallery', 'ez_portfolio_gallery_fields', 'post' );
  31. }
  32.  
  33. function ez_portfolio_gallery_fields(){
  34. ?>
  35.    
  36.     <label for="ez_portfolio_gallery">Image URL:</label><br />
  37.     <input type="text" class="widefat" id="ez_portfolio_gallery" name="ez_portfolio_gallery" value="" /><br />
  38.    
  39. <?php
  40.    
  41.     $mykey_values = get_post_custom_values( 'ez_portfolio_gallery', $post_ID );
  42.     foreach ( $mykey_values as $key => $value ) {
  43.     echo "$key  => $value <br />";
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement