• Resolved phpwppro

    (@phpwppro)


    Hi there, your plugin is very useful to create custom post type…!!

    I have created a custom post type called friend_request now what i want to do when user delete the post type friend_request, i want to redirect them to front page of site so that i created a plugin which simply redirect them to front-page of site which is working in localhost but its not working on live..!

    Here is the plugin code
    <?php
    /*
    * Plugin Name: Redirect on deleting post type friend_request
    */
    add_action( ‘trashed_post’, ‘redirect_after_trashing’, 10, 1 );

    function redirect_after_trashing( $post_id ) {
    global $post;

    // get the deleted post types
    $deleted_post_type = $post->post_type;

    if($deleted_post_type == ‘friend_request’) {
    wp_redirect( home_url() );
    exit();
    }
    }

    Please help me on this case..!

    Thanks!

    https://ww.wp.xz.cn/plugins/custom-post-type-ui/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Perhaps try this:

    <?php
    /*
    * Plugin Name: Redirect on deleting post type friend_request
    */
    function redirect_after_trashing( $post_id ) {
    
    	$the_post = get_post( $post_id );
    
    	// get the deleted post types
    	$deleted_post_type = $the_post->post_type;
    
    	if( $deleted_post_type == 'friend_request' ) {
    		wp_redirect( home_url() );
    		exit();
    	}
    }
    add_action( 'trashed_post', 'redirect_after_trashing', 10, 1 );

    Makes use of the $post_id that gets passed in. My best hunch is that the $post global is maybe not being set like expected for some reason, between environments.

    Thread Starter phpwppro

    (@phpwppro)

    Hi, thanks for your reply
    I tried your code but its not working 🙁
    what else to do?

    Thanks

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Dunno what to tell ya then, it’s a question that’s really outside the scope of our plugin.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Redirect after deleting post’ is closed to new replies.