I want to display a message like “You must be logged in to view this”, with Private custom posts. Theoretically, I want to use something like this:
if (is_user_logged_in()) {
// Page code goes here
}
else {
echo "You must be logged in to view this page.";
}
This code is in the single-custom.php page template.
The true
case works just fine. However, if the user is not logged in, instead of seeing “You must be logged in…” I get a 404 instead? What am I doing wrong?
Are you doing this inside The Loop? I’d try something like this myself: