My custom post type redirect to edit.php after publish and update post in wordpress

php, redirect, wordpress

Solution

You need to use get_post_type() function.

Change your code to

function wpse_124132_redirect_post_location( $location ) {

    if ( 'deals' == get_post_type() ) {

    /* Custom code for 'deals' post type. */

        if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) )
            return admin_url( "edit.php?post_type=deals" );

    } 
    return $location;
} 

EDIT : Since you are using `get_post_type()` outside of The Loop you'll need to pass the ID of the post,

`get_post_type($_POST['id'])`

Problem

I have created new custom post type - deals in wordpress and it is redirect to edit.php(posts listing) after the publish new deal post. so I want to redirect it to deals list page (http://mydemo.com/demo/edit.php?post_type=deals) so please help me. I tried this code but it redirect all posts type to specified page. ``` add_filter( 'redirect_post_location', 'wpse_124132_redirect_post_location' ); /** * Redirect to the edit.php on post save or publish. */ function wpse_124132_redirect_post_location( $location ) { if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) return admin_url( "edit.php?post_type=deals" ); return $location; } ```

Original source