Are you doing this inside The Loop? I’d try something like this myself:
if ($post->post_status == "private" && !is_user_logged_in()) {
echo "You must be logged in to view this page.";
} else if( $post->post_status == "private" && is_user_logged_in() ) {
// Page code goes here
}
Related Posts:
- Custom post type permalink returns 404 when set to private
- Custom post type single page returns 404 error
- Getting hierarchical custom post type permalinks to work just like pages
- Custom post type pagination 404 fix?
- How do I require authorization / login to view a specific set of posts / pages?
- Inconsistent temporary 404s on whole install | PHP error with post-template.php
- Set posts of a custom post type to be private by default?
- Custom post type 404s with rewriting even after resetting permalinks
- Custom Post Types 404 Issue
- Custom post type archive 404’s with paginate_links
- Pagination throws 404 error on custom taxonomy archive pages
- 404 on child page when parent page slug is identical to custom post type
- Fetching private posts or custom post types via WP-API with basic authentication
- Single custom post type page redirecting to 404 page
- Hierachical Custom post types permalinks not working
- How to disable a Custom Post Type Feed?
- How can i avoid the permalink start with ‘blog’ while using the custom post type?
- Child pages on hierarchical Custom Post Types 404s
- Custom Post Type Works but Still Shows “Page Not Found”
- WordPress custom post type category pagination 404 Error
- Pagination throws 404
- How do I redirect all 404 errors of a specific post type to another URL?
- Removing CPT slug from URL results in 404 error for archive page
- WordPress monthly archive links result in 404
- Remove Slug from Custom Post Type results in 404
- How to remove CPT comment feed from head?
- Custom Taxonomy archive returns 404
- Pagination gives 404 error
- Custom Taxonomy 404
- Pagination with custom post types results in 404 issues
- Create second custom 404 page for selected post type
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- Disable comments from showing up public for Custom Post Type
- 404 error on custom post type
- Making a Custom Post type only visible to non-users via a specific link
- Multisite custom post type’s single page 404
- custom post type and custom taxonomy url conflict
- Why my custom post posts aren’t showing (404 error / page not found)
- An empty Custom Post Type Archive page returns 404 in WP 3.1
- How To Create A Custom Taxonomy 404 Page
- Custom Post Type + 20k posts = blank/404 within Admin edit.php [duplicate]
- Comprehensively Restrict Post Type Taxonomy to Logged-in Users
- Bizarre Permalinks Issue: 404 Errors Everywhere
- Custom taxonomy in URL showing 404
- Custom Post Type Draft Preview Goes to 404
- query private custom post type
- page not found for single-type.php file
- Custom taxonomy page returns 404
- One Custom post type 404’s others don’t
- Custom taxonomy template list not working (404)
- Custom post type slug 404
- How to filter a custom post type by custom taxonomy without 404
- Custom Post 404
- Custom taxonomy template shows 404 Error
- Post type Permalink
- Custom post type categories gives 404 error
- Direct form to a custom page template
- Have custom post type Visibility be private by default, and have radio button also set to “Private”
- Permalink Trouble with custom post types
- Permalinks not working (404) for the ‘item’ post type
- Safe to throw 404 error in request filter?
- either single-{custom}.php 404’s OR /taxonomy/ 404’s – custom post type and taxonomy permalinks
- Easiest way to have closed comments on a custom post type
- Custom Post Type Child Won’t Come Through With Pretty Permalinks
- Problem with custom loop navigation inside the blog page
- Can’t Export Custom Post Types With Export Tool In A Custom Theme
- Custom post type single page 404
- Sudden 404 pages on product category archives
- Forcing two or more custom post type to be private
- Custom taxonomy returns 404 even with saving permalinks
- Show custom post status when logged out
- Custom post shows 404 after theme change
- How can I get custom post types to recognize pretty permalink variables?
- Enabling hierarchical in a Custom Post Type gives error 404
- Standard Page Child of CPT Not Found (404)
- Custom Post Type Front Page Gives 404
- Published page but it is page not found
- Pagination for custom query returns 404
- New entries to custom post type produce 404 on single view
- Custom Post Type slug and WPML gets 404 error
- Add new custom post type screen (admin area) results into 404
- Some permalinks on Apache/localhost development setup return 404’s when set to anything other than plain permalinks
- Making permalink for custom post type/custom taxonomy. Stuck with 404 in the single post
- pre_get_posts gives 404 error on Custom Post
- Custom 404 redirect for a luddite
- WP gives 404 error for custom post type with GET variable
- 404 error next-page [2] PageNavi custom type taxonomy
- Custom Post Type Rewrite – Page Not Found
- What am I doing wrong with my taxonomy?
- Cannot use pages created on WP
- CPT unsaved draft gives error 404 – when Post Formats support enabled
- Pages displays correctly but returning a 404 error in http header.
- Pagination in custom loop for custom post type throwing 404 error
- 404 for children in hierarchical custom post type
- Submiting custom form give error 404
- 404 with Custom Post Type
- How do I paginate a custom post type listing on a custom template page?
- WordPress custom post type post and category links 404
- 404 Error On Custom Taxonomy Pages 2, 3, etc