Redirect user away from an event page

WordPress Event Management, Calendars & Registration Forums General Question Redirect user away from an event page

This topic contains 1 reply, has 1 voice, and was last updated by  Robert Stankey 3 years, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #39390

    I have a scenario where users have bookmarked a direct link to an event page (that has recurring events) and I want them redirected to a login page first. I’ve seen many examples of code online where you can redirect if a certain page is displayed, such as:

    add_action( 'admin_init', 'redirect_non_logged_users_to_specific_page' );
    function redirect_non_logged_users_to_specific_page() {
      if ( !is_user_logged_in() && is_page('add page slug or ID here') {
        wp_redirect( 'http://www.example.dev/page/' ); exit; }
    }

    I think I can get the redirect to work by making slight modifications to this example but I’m not sure when you view an event it is a page, event, or something else. Any tips you provide me?

    Thanks,
    Robert

    Robert Stankey
    #39392

    I figured out how to make this work for what I needed…..

    add_action( ‘template_redirect’, ‘redirect_non_logged_users_to_specific_page’ );
    function redirect_non_logged_users_to_specific_page() {
    global $wp_query;

    if(get_query_var('post_type') == 'event') {
        if(!is_user_logged_in() && ($wp_query->post->post_name == 'family-class' || $wp_query->post->post_name == 'black-belt-class-2')) {
            wp_redirect( 'https://www.kimsacademy.com/classes-reservations-login/');
            exit;
        }
    }
    

    }

    Thanks,
    Robert

    Robert Stankey
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.