Reputation: 6380
I've created a delete post button on the front end for a Wordpress site. It deletes the post fine but then tries to reload the post again causing a 404. Is there a way I redirect it after deleting to a specific url? This is my code:
function wp_delete_post_link($link = 'Delete This', $before = '', $after = '') {
global $post;
$link = "<a href='" . wp_nonce_url( get_bloginfo('url') . "/wp-admin/post.php?action=delete&post=" . $post->ID, 'delete-post_' . $post->ID) . "'>".$link."</a>";
echo $before . $link . $after;
}
Then on the template:
<?php wp_delete_post_link('Delete This', '<p>', '</p>'); ?>
Upvotes: 0
Views: 1464
Reputation: 2679
I think you are looking for the wp_redirect
function.
$location = 'http://domainname.com/pagename/';
$status = '301';
wp_redirect( $location, $status );
exit;
Just place after your successful delete code.
Upvotes: 1
Reputation: 1
How about running this function right after your echo:
header( 'Location: yournewURL.html' ) ;
Replace 'yournewURL.html' with the page you need to redirect to.
Upvotes: 0