如果这是在admin中,请使用action
参数:
<a href="<?php echo esc_url( admin_url( "?action=delete_ticket&ticket_id=$ticket->ID" ) ?>">Delete item</a>
。。。然后适当挂钩:
function wpse_159391_delete_ticket() {
if ( isset( $_GET[\'ticket_id\'] ) ) {
// delete it!
}
}
add_action( \'admin_action_delete_ticket\', \'wpse_159391_delete_ticket\' );
对于前端,您只需将参数附加到当前url,并在
template_redirect
:
function wpse_159391_delete_ticket() {
if ( isset( $_GET[\'delete_ticket\'] ) ) {
$ticket_id = $_GET[\'delete_ticket\'];
// delete it!
}
}
add_action( \'template_redirect\', \'wpse_159391_delete_ticket\' );
要在处理后重定向,请执行以下操作:
// Get the URL of the current page/post
if ( is_singular() )
$url = get_permalink( get_queried_object_id() );
// Get custom URL
$url = home_url( \'my/url/path?arguments\' );
// Get current URI with removed arguments
$url = remove_query_arg( \'delete_ticket\' );
// Get current URI with added arguments
$url = add_query_arg( \'success\', \'true\' );
wp_redirect( $url );
exit;