SHARE
TWEET

Untitled

a guest Jul 12th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action('save_post', 'save_my_post_meta');
  2.  
  3. function save_my_post_meta($post_id) {
  4.     // Bail if we're doing an auto save
  5.     if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
  6.  
  7.     // if our current user can't edit this post, bail
  8.     if( !current_user_can( 'edit_post' ) ) return;
  9.  
  10.     // now we can actually save the data
  11.     $allowed = array(
  12.         'a' => array( // on allow a tags
  13.             'href' => array() // and those anchors can only have href attribute
  14.         )
  15.     );
  16.     // If any value present in input field, then update the post meta
  17.     if(isset($_POST['mytext'])) {
  18.         // $post_id, $meta_key, $meta_value
  19.         update_post_meta( $post_id, 'mytext', $_POST['mytext'] );
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top