# Send Single Entries of a Post Type to Its Archive

> Redirects the single pages of post types that only make sense in a list, such as testimonials, FAQs or team members, to their archive or another page.

- Type: PHP
- Runs: Run everywhere
- Category: [Redirects](https://wpide.com/library/category/redirects/)
- Tags: post-types, redirect, archives
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/redirect-post-type-singles-to-archive/

## Code

```php
// Post types whose single pages redirect.
$wpide_list_only_types = array( 'testimonial' );
// Optional fixed target path, such as '/reviews/'. Leave empty to use the archive.
$wpide_list_only_target = '';

add_action( 'template_redirect', function () use ( $wpide_list_only_types, $wpide_list_only_target ) {
    if ( ! is_singular( $wpide_list_only_types ) ) {
        return;
    }

    if ( '' !== $wpide_list_only_target ) {
        $target = home_url( $wpide_list_only_target );
    } else {
        $archive = get_post_type_archive_link( get_post_type() );
        $target  = $archive ? $archive : home_url( '/' );
    }

    wp_safe_redirect( $target, 301 );
    exit;
} );
```

## Notes

Set the post types and, optionally, a fixed target path. Without a target, the post type archive (or the homepage) is used.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Single Entries of a Post Type to Its Archive" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
