On further thought, I would have my PHP form handler code avoid initiating the WP environment, contrary to what I said earlier. The PHP form handler code could send a Location:
header to effect the redirect. You’ll need to hardcode the WP URL since site_url()
will be unavailable (or get it from $_SERVER
). Hardcoding means this would be unsuitable as a distributed plugin solution, but is more efficient as a custom site specific solution. The PHP form handler file can reside anywhere on your server, it’s not part of WP.
<?php
header('Location: https://my-wp-site.com/?p=' . (int) $_REQUEST['code']);
exit;
Assuming the above PHP is in /inc/my-redirect.php, your HTML form might look like this:
<form action="https://my-wp-site.com/inc/my-redirect.php">
<label for="code">Page ID:</label>
<input type="text" name="code" id="code">
<input type="submit" value="Go">
</form>