Advertisement
Guest User

Untitled

a guest
Jul 12th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement