Set post types to private by default

smartsovereign
18 May 2022

Sometimes you have a post type that needs to stay private, like video tutorials for your clients or a quotes for products that should not be seen by the public or indexed by the search engines.

The snippet below will allow you to set all posts from a given post type to private by default.

function force_type_private($post){if ($post['post_type'] == 'my_post_type')$post['post_status'] = 'private';return $post;}add_filter('wp_insert_post_data', 'force_type_private');

Remember : Change “my_post_type” to your custom post type.

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy