Say that I want to make a post type called ‘press’ and it is mostly concerned with linking a title with a PDF document of a press clipping. I want to show all of these as an archive… so something like site.com/press but i don’t want any single post template pages. so no site.com/press/article1 or site.com/press/article2. other than not including a link in my archive template (which just obscures it but doesn’t negate their existence or prevent access to the single posts) how can i prevent a visitor from inadvertently accessing the single posts. how could i re-direct them back to the /press archive?

2 s
2

The fast way

In your .htaccess add a rule

RedirectMatch Permanent ^/press/.+ /press/

Plugin way

Hook into template_redirect and redirect all requests to a single entry:

add_action( 'template_redirect', 'wpse_45164_redirect_press' );

function wpse_45164_redirect_press()
{
    if ( ! is_singular( 'press' ) )
        return;

    wp_redirect( get_post_type_archive_link( 'press' ), 301 );
    exit;
}

(Caveat: not tested)

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *