Redirect User Login after checking posts
-
Hi guys, I am hoping someone will be able to point out what I am missing or doing wrong. I have a front end form where posts are submitted. On the initial login users are directed to the form which is correct. As every user will only have one post. I want subsequent logins by the user to be directed to his own summary page. In order to do this, I need wordpress to check if the $current_user already has a post if so redirect to summary if not to form.
The following is the code I have created in my functions.php file:function redirect_user() { global $wpdb, $current_user; get_currentuserinfo(); $check_posts = $wpdb->get_results("SELECT * FROM $wpdb->wppj_posts WHERE post_type = 'post' AND post_author = $current_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);The problem is that it redirects to same page whether the user has a post or not.
The topic ‘Redirect User Login after checking posts’ is closed to new replies.