Site icon Hip-Hop Website Design and Development

The way to move a message utilizing template_redirect

I am utilizing the next operate to redirect a publish to a different utilizing customized subject. It is working simply effective till I added the line#8 to move an ID in order that I can seize it in to the publish (to the place was redirected), and present a customized message that, you might be redirected from that specific publish:

operate project_do_redirect() {
    if( !is_singular( 'mycpt' ) && !is_single() )
        return;

    world $publish;
    $redirect_post_id = get_post_meta( $post->ID, 'redirect', true );
    $redirect_url = $redirect_post_id ? get_permalink( $redirect_post_id ) : false;
    $redirect_url = esc_url( add_query_arg( 'redir_from', $post->ID, $redirect_url ) );
    if( $redirect_post_id ) {
        wp_redirect( $redirect_url, 301 );
        exit;
    }
}
add_action( 'template_redirect', 'project_do_redirect' );

Downside is:
If I used to be redirected from publish #12 to publish #13, the ?redir_from= reveals 13 as a substitute of 12. So the factor shouldn’t be truly working as anticipated.

So, with out passing any parameter to the URL, how can I move a message to the redirected web page?