WordPress | Redirect all Single Posts of a Custom Post Type to Custom Post Type Archive

I need to redirect all Custom Singles Post type to relative Custom Post Type archive.

Open your theme’s function.php

and add this snippet of PHP:

add_action( 'template_redirect', 'redirect_post_type_single' );

    function redirect_post_type_single(){
      $post_type = 'partners'; // Define the custom post type you want to redirect
      $post_type_archive_url = get_post_type_archive_link( $post_type ); // Retrive url of relative Custom post Type Archive
        if ( ! is_singular( $post_type ) ) // Check if is singular
        wp_redirect( $post_type_archive_url, 301 ); // Redirect to archive

Navigate to the single custom post type you have defined in the ” $post_type ” var, and you’ll be redirect to the Post Type Archive page ( defined in ” $post_type_archive_url ” ).

That’s all

Have a nice day !!