Delete custom post type in front end and redirect to specific page

Question

I made it possible to delete the post from the front end with this code (get_delete_post_link redirect):

<a class="button-iv" onclick="return confirm('are you sure...?');" href="<?php echo get_delete_post_link( $post->ID ); ?>" title="delete doc">Delete doc</a>

In functions.php i have this code for redirect after deleting the post:

function wpse132196_redirect_after_trashing_get() {
    if ( array_key_exists( 'trashed', $_GET ) && $_GET['trashed'] == '1' ) {
    if (!is_admin()) {
       wp_redirect( home_url('/doc-area/doc') );
       exit;
    }
    }
}
add_action( 'parse_request', 'wpse132196_redirect_after_trashing_get' );

This works fine. But now I would like to create a different redirect for each custom post type.
So I add this control

if ( 'extra' == get_post_type() )

And the function become:

function wpse132196_redirect_after_trashing_get() {
if ('extra' == get_post_type()) {
    if ( array_key_exists( 'trashed', $_GET ) && $_GET['trashed'] == '1' ) {
    if (!is_admin()) {
        wp_redirect( home_url('/doc-area/doc') );
        exit;
       }
      }
    }
}
add_action( 'parse_request', 'wpse132196_redirect_after_trashing_get' );

But now the redirect doesn’t work.
How can I get a redirect for each specific post type?

0
Andrea A 4 weeks 2021-04-11T10:12:59-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse