I'm trying to make the front-end login for Wordpress redirect to the post (in a custom post type) that was automatically created when they registered.
I can get the URL I want to redirect them with a wp_query. I imagine this is not the best way to do it, but I don't know enough php to figure it out. Here's my current attempt, but it just prints the url (the right one, at least!) on a blank page with the same login url they were already at:
function my_login_redirect( $redirect_to, $request, $user ){
global $user, $post;
$args = array(
'author' => $current_user->ID,
'post_type' => 'course-providers',
'showposts' => 1,
'caller_get_posts' => 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php wp_redirect ( the_permalink () ); ?>
<?php
endwhile;
} else {
echo "This User Has no Profile";
}
}
add_filter("login_redirect", "my_login_redirect", 10, 3);
Also, I imagine I don't need the wp_redirect and that I should just be using the login_redirect filter itself, but again, I'm pretty lost right now and just taking lots of shots in the dark.
Thanks for the help, and let me know if there's additional info that would make this more helpful for others or easier to answer. Thanks!
header("Location: /correctURL");
redirect? – Kevin Lynch