Viewing 1 replies (of 1 total)
  • Thread Starter AnotherChance

    (@anotherchance)

    Right, managed to sort this out. I changed my code to,

    function redirect_user() {
    	global $wpdb, $user;
    
    	$check_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_author = $user->ID");
    
    	if(!$check_posts) {
    		wp_redirect(site_url('/update-profile/'));
    	} else {
    		wp_redirect(site_url('/summary/'));
    	}
    	exit;
    }
    add_filter('login_redirect', 'redirect_user', 10, 3);

    According to Codex “The $current_user global may not be available at the time this filter is run. So you should use the $user global or the $user parameter passed to this filter.”

Viewing 1 replies (of 1 total)

The topic ‘Redirect User Login after checking posts’ is closed to new replies.