I access the page like:
example.com?step=3
Until here, it works, if I use $_GET['step']
its ok, its 3.
But, after step 3 do what it needs to do, I call:
wp_redirect( add_query_arg( 'step', 4 ) );
Looking on network tab at Devtools it does access with 302 as: example.com?step=4
But at the page $_GET['step']
is still 3! Than it enters in an infinite loop.
I logged $_SERVER['QUERY_STRING']
and it is as expected step=4
, but right on the next line I call $_GET['step']
and it is 3!
When I access directly example.com?step=4 it works, $_GET['step']
is 4, but when I use wp_redirect();
it doesnt.
Can some one help?
I think your problem is that you are not clearing out the old “step” before adding the new one.
add_query_arg()
doesn’t update the string, it adds to it.So try doing something like…
wp_redirect(esc_url(add_query_arg(‘step’ => ‘4’,$origURL)));