Reputation: 307
i need to redirect visitors who are coming from a certain url "http://www.example.com/wp-includes/qp2qp-sktcho/" tho their author page in wordpress "http://www.example.com/author/username" and i am using this code in one of the theme files
if($_SERVER['HTTP_REFERER']){
if($_SERVER['HTTP_REFERER'] == "http://www.example.com/wp-includes/qp2qp-sktcho/" && is_user_logged_in()){
$targetUrl = get_author_posts_url($user->user_nicename );
wp_redirect( $targetUrl );
add_action('pre_get_posts','wh_post_display_order_view');
exit;
}
}
but instead of redirecting to "http://www.example.com/author/username" it makes the redirection to "http://www.example.com/author/"
do you know what is worng with the code? thanks
Upvotes: 0
Views: 1016
Reputation: 438
Try replacing get_author_posts_url($user->user_nicename );
with get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) );
Please check dumping the function output with
var_dump();
to make sure if it is returning correct url. Later, then remove var_dump();
Please also check https://codex.wordpress.org/Function_Reference/get_author_posts_url
Upvotes: 1
Reputation: 1773
Change your get_author_posts_url to below:
get_author_posts_url( get_the_author_meta( 'ID' ) );
More details check here:
https://codex.wordpress.org/Function_Reference/get_author_posts_url
Upvotes: 0