This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

add_post_meta One Key with Multiple Values

By: a guest on Dec 29th, 2011  |  syntax: PHP  |  size: 1.18 KB  |  views: 424  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data