Redirection help
-
Hello, I am trying to run a check when a user visits a certain page to see if the current user has a published or draft posts of a custom post type. If they do, then I’m trying to redirect them. I’ve found some posts, but no luck in putting it all together to fit my needs. I can understand the template redirect function a bit easier, so I’ve tried to go that route. But I’m not sure if that’s the best way to do it.
I’ve tried to work with these snippets:
Here’s what I’ve have so far:
add_action( 'template_redirect', 'redirect_to_specific_page_resume' ); function redirect_to_specific_page_resume() { global $post; $current_user = $post->post_author; if(!empty($current_user)){ $user_post_count = (int) count_user_posts( $current_user ); if ( is_page('479') && $user_post_count == 1 ) { wp_redirect( "/myaccount/manage-resumes", 301 ); exit; } } }
This is what should happen:
If current user goes to PAGE ONE and is a published or draft author of a custom post type, then redirect to PAGE TWO. If current user goes to PAGE ONE and is NOT a published author of a custom post type, do nothing, load PAGE ONE as normal.Thank you. ??
- The topic ‘Redirection help’ is closed to new replies.