In post_meta after “add new” how to redirect to list page

I am using register_post_type to create post_meta so in “add new” functionality after adding and publish it is redirecting to “edit page”. How I can redirect it to list page after publish?

Related posts

Leave a Reply

1 comment

  1. You can use redirect_post_location action hook to redirect your post type to location or url you need after editing or publishing.

    function custom_redirect($location) {
    
        global $post_type;
    
        if ($post_type == 'your post type here') {
            $location   = admin_url('edit.php?post_type=' . $post_type);
        }
    
        return $location;
    }
    
    add_action( 'redirect_post_location', 'custom_redirect');
    

    It checks for your post type and create the url to the list page of your post type and set new redirect locations.

    Hope this helps you 🙂