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(){



If 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') ) );

or multiple parameters

wp_redirect( add_query_arg( array( 'notice' => 'success', 'foo' => 'bar' ), get_site_url(null, '/redirect_to_two') ) );

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.

  • Data in variables are gone but i still have in url something like mysite/login?notice=success and i not want this. If someone go back and return then is not good. I refresh site and still is.
    – Jaron
    Mar 28 '19 at 21:05
  • What if you removed the query parameters with javascript from the url? Or would creative use of transients be applicable? E.g. after the save function create a one-use random string as a transient and add the same string as a query parameter to the redirect url. After redirect match the parameter and the transient to trigger a notice. Delete the transient afterwards. Mar 29 '19 at 11:45
  • Could perhaps use a cookie, then delete it after the redirect. But that wouldn't work if the browser had disabled them. There could still be an issue with returning to the site. Could perhaps put a quite short expiration time on the cookie. Mar 30 '19 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.