Keep user session with custom implementation of user login
To implement custom user login functionality outside of the wp-admin area, wp_signon() function is the way to go. This function accepts an array which may contain the “remember” key with a boolean value to determine if the user shall stay logged in or not during the following 14 days.