tareq1988

Save Post Meta

Apr 22nd, 2012
42
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function wedevs_save_top( $post_id ) {
  4.     // make sure something has been submitted from our nonce
  5.     if ( !isset($_POST[$key . '_wpnonce']) )
  6.         return $post_id;
  7.        
  8.     // verify this came from the our screen and with proper authorization,
  9.     // because save_post can be triggered at other times    
  10.     if ( !wp_verify_nonce($_POST[$key . '_wpnonce'], basename(__FILE__)) )
  11.         return $post_id;
  12.    
  13.     // verify if this is an auto save routine.
  14.     // if it is our form and it has not been submitted, dont want to do anything
  15.     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
  16.         return $post_id;
  17.  
  18.     // lastly check to make sure this user has permissions to save post fields
  19.     if ( !current_user_can('edit_post', $post_id) )
  20.         return $post_id;
  21.        
  22.     if( isset( $_POST['top_ad'] ) ) {
  23.         update_post_meta( $post_id, 'top_ad', $_POST['top_ad'] );
  24.     }
  25. }
  26.  
  27. add_action( 'save_post', 'wedevs_save_top' );
RAW Paste Data