Support

Account

Home Forums Backend Issues (wp-admin) Default to current user with user field Reply To: Default to current user with user field

  • Hi!

    I honestly think you’ll be better of creating this yourself..

    simply do an update_post_meta on the wp_save_post hook.. something like this (not tested):

    
    function save_book_meta($post_id) {
    
        $slug = 'book'; //CHANGE THIS TO THE SLUG OF YOUR POST TYPE
    
        /* check whether anything should be done */
        $_POST += array("{$slug}_edit_nonce" => '');
        if ( $slug != $_POST['post_type'] ) {
            return;
        }
        if ( !current_user_can( 'edit_post', $post_id ) ) {
            return;
        }
    
    $current_user = wp_get_current_user();
       update_post_meta($post_id, 'latest_author', $current_user-> display_name);
      
    }
    
    add_action( 'save_post', 'save_book_meta');
    
    

    This will save the current users display name as a custom field called “latest_author”.