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?

1 Answer 1


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.

  • 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, 2012 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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