Restrict Post Type Access
Overview
Restrict public access to selected custom post types. The snippet checks archive and single views for the configured post type slugs, then redirects visitors who do not have the required capability to the WordPress login URL.
Replace the placeholder post type slugs in $protected_post_types with the CPT slugs for the site. By default, the access check uses current_user_can( 'edit_posts' ).
Variants
- Procedural