Recently one of my client asked me to redirect her viewers ( who wants to check her profile page) to the Login page if the viewers are not logged in. As the profile page are of Custom Posts. I have tried to solve the issue using the following code.
<?php
$page_id = get_queried_object_id();
if ( !is_user_logged_in() && get_post_type($page_id) =='YourCustomPostType' )
{
header('Location: http://www.YourLoginPageURLHere.com');
}
?>