CPT protection

If you want to protect a custom post type (CPT) in WordPress to be only available to logged-in users or make sure they login.

function some_func( $query ){
if ( is_post_type_archive('nieuwsbrief') && !is_user_logged_in() ) {
// Do stuff
wp_redirect('/wp-login.php'); }
}
add_action('pre_get_posts','some_func');

Leave a Reply

Your email address will not be published. Required fields are marked *