Here's the deal. Let's say I have a custom post type called "subscriptions". Under this post type there are pages like the following:

  • mysite.com/subscription/my-first-subscription
  • mysite.com/subscription/my-second-subscription
  • mysite.com/subscription/my-third-subscription

The issue is that I actually have a pricing page which allows users to use a widget to select the different subscriptions. I don't want the users to ever be able to access the subscription pages directly, even if they know the URL. My first thought is that I'd like any attempt to access a page of "subscription" type to be redirected to the pricing page. How would I do that?

(If someone has a better idea, I'm open to that as well.)


1 Answer 1


As stated by Milo it looks like it a duplicate of [How to disable the single view for a custom post type?]

add_action( 'template_redirect', 'subscription_redirect_post' );

function subscription_redirect_post() {
  $queried_post_type = get_query_var('post_type');
  if ( is_single() && 'subscription' ==  $queried_post_type ) {
    wp_redirect( pricingpageURL, 301 );

Just swap our pricingpageURL with the pricing page URL value of your choice. Hope this helps.

  • How would I check to see if the subscription page contained a particular taxonomy? I'm not sure which variables are exposed at this point.
    – Pete
    Commented Dec 30, 2014 at 17:22
  • Nevermind, I got it. Looks like get_the_id() works, so I just used has_term(). Thanks!
    – Pete
    Commented Dec 30, 2014 at 17:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.