Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using a lot of custom post types for creating sidebars, footers, etc and would like to hide direct viewing of these post types. Is this possible?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

register_post_type allows you to specify whether a post is 'publicly_queryable'

publicly_queryable (boolean) (optional) Whether queries can be performed on the front end as part of parse_request().

Default: value of public argument Note: The queries affected include the following (also initiated when rewrites are handled)

  • ?post_type={post_type_key}
  • ?{post_type_key}={single_post_slug}
  • ?{post_type_query_var}={single_post_slug}

It doesn't mention anything about queries of the form ?p=, and from memory, these will still serve your custom post types event with the publicly_queryable set to false. To prevent this you can hook onto template_redirect and redirect to a different (404?) page.

share|improve this answer
    
Thanks, exactly what I was looking for. I also tested it with ?p= query and it still delivers a 404 which is what I want. –  Ian Hoar Aug 13 '12 at 22:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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