Restrict frontend CPT by custom user role

I am trying to restrict a custom post type from being viewed on the frontend by a custom user role ‘trade’, created by User Role Editor. If a user isn’t logged in, they should redirect to the signup form (a Gravity Form)

I have the following in functions.php which isn’t working

if ( is_singular( 'furniture' ) || is_post_type_archive( 'furniture' ) ) {

add_action( 'loop_start', 'check_wholesale_group' );
function check_wholesale_group() {

    if ( !is_user_logged_in() ) {
        wp_redirect( 'https://www.domain.com/trade-signup' );
        exit;
    }

}

}

Read more here: Restrict frontend CPT by custom user role

Leave a Reply

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