1

This question already has an answer here:

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.)

marked as duplicate by Milo, Pieter Goosen, fuxia Dec 30 '14 at 19:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

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

<?php
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 );
    exit;
  }
}
?>

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 Dec 30 '14 at 17:22
  • Nevermind, I got it. Looks like get_the_id() works, so I just used has_term(). Thanks! – Pete Dec 30 '14 at 17:27

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