I want add text to array and display after redirect and unset array.
class test{
public function one(){
$this->save(2, 'some');
$url = get_site_url(null, '/redirect_to_two');
wp_safe_redirect( $url );
}
public function two(){
$this->display();
}
}
I want add text to array and display after redirect and unset array.
class test{
public function one(){
$this->save(2, 'some');
$url = get_site_url(null, '/redirect_to_two');
wp_safe_redirect( $url );
}
public function two(){
$this->display();
}
}
Share
Improve this question
edited Jul 21, 2019 at 23:37
Jaron
asked Mar 28, 2019 at 19:50
JaronJaron
458 bronze badges
1 Answer
Reset to default 1If you need to pass some data over the redirect, you can do that by adding parameters to the redirect url with add_query_arg()
. But other more elegant solutions might exist also.
Single parameter,
wp_redirect( add_query_arg( 'notice', 'success', get_site_url(null, '/redirect_to_two') ) );
exit;
or multiple parameters
wp_redirect( add_query_arg( array( 'notice' => 'success', 'foo' => 'bar' ), get_site_url(null, '/redirect_to_two') ) );
exit;
Then use $_GET
to grab the parameter(s),
if ( ! empty( $_GET['notice'] ) && 'success' == $_GET['notice'] ) {
// Do whatever.
}
If I'm not mistaken, I don't think you need to worry about unsetting arrays as data doesn't normally persist in WordPress. Once you do a redirect all the data in your $variables
are gone.