我以前使用过WordPress的自定义帖子处理程序功能来解决与您遇到的问题类似的问题。以下是codex关于这方面的文件:https://codex.wordpress.org/Plugin_API/Action_Reference/admin_post_(action)
基本上,您将使用一个操作来处理post请求:
function my_handle_form_submit() {
// This is where you will control your form after it is submitted, you have access to $_POST here.
}
// Use your hidden "action" field value when adding the actions
add_action( \'admin_post_nopriv_my_simple_form\', \'my_handle_form_submit\' );
add_action( \'admin_post_my_simple_form\', \'my_handle_form_submit\' );
并修改表单a,以便WordPress知道如何使用您的函数来处理请求:
<!-- Submit the form to admin-post.php -->
<form action="<?php echo esc_url( admin_url(\'admin-post.php\') ); ?>" method="POST">
<!-- Your form fields go here -->
<!-- Add a hidden form field with the name "action" and a unique value that you can use to handle the form submission -->
<input type="hidden" name="action" value="my_simple_form">
</form>