I've created a button on my Wordpress
site which allows my users to change their location from 'London'
to 'Manchester'
.
The button uses $_POST
to start a PHP function.
As part of that PHP
function I want to 'clean'
the URL
of the page the user is on (i.e. remove the query strings) because if there are any query strings when they change locations it can mess things up when they try and use filters.
I've found a way to get a clean URL
$url=strtok($_SERVER["REQUEST_URI"],'?');
And I thought I might be able to use
wp_redirect($url);
To refresh the page with a clean URL
- but doesn't seem to work.
I think the reason this question is unique is it is related to a function that is started by a $_POST request, rather than hooked to an action which is being loaded. As a result, the page isn't fully reloaded. I have looked at other questions which tell me how to remove the query string (which is helpful enough) but not redirect me at the end.
Any thoughts much appreciated.