I am trying to redirect frontend users after deleting their post from frontend. I am using the get_delete_post_link and then redirecting by using the following code:
add_action( 'trashed_post', 'dex_redirect_after_trashing', 10 );
function dex_redirect_after_trashing() {
$authorName = get_the_author_meta( 'user_nicename' );
$myWeb = home_url('/');
$targetUrl = $myWeb . $authorName;
wp_redirect( $targetUrl );
exit;
}
I am trying to redirect to a url format like this "www.mysite.com/$author
"
Currently its redirecting to the home url.
Desclaimer: I am a newbie.
2
Answers
As pointed by CBroe above in the comments, the
get_the_author_meta
needed author ID as a second parameter. Here is the revised code:The code is working as it supposed to be. Any further improvement or critic is appreciated.
You are missing the
/author/
part in the Link.