register_post_type() has quite a few related arguments, of which publicly_queryable controls precisely what you are describing.
However note that it will completely kill the CPT on front end — individual posts, archives, even post previews.
If you want to do this conditionally you’ll have to manage this with code from scratch, which might get very involved to do comprehensively.
Related Posts:
- Submit post and upload image from front-end
- Linking Two Post Types
- Pull Two Posts Into Custom Post Type `single-cpt.php`
- Problem excluding category from get_next_post
- Why is the »_builtin« parameter not advised in »register_post_type()« for custom post types?
- How to let custom post type posts show in standard post archive (like in homepage)?
- Rewrite custom post & taxonomy to share same URL path
- Get the post children count of a post
- Quickest way to get last or oldest post date – WP Query
- How to use custom fields to enable sticky posts on custom post types?
- get_template_part for custom post type content not working
- Show Two custom Post type and their posts on category page
- count_many_users_posts except current logged in user?
- Custom post type and body_class: Remove “blog” class
- Find the user who initially created the post
- How to get the post type from a category id?
- Is there a way to have the view link on manage posts page to open in a new window or tab?
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Getting posts under the custom post type ui category
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Set a checkmark in a category based on a URL-parameter
- Portfolio Page for Classic Posts
- Limit the post for differents custom post type in the same wp_query
- 2 Different Custom Post Types in Submenu
- How to assign classes to all elements?
- How can I show 1 featured post in a styled element, and the next few below differently styled
- Reworking function for counting custom post type posts count
- help
- wp_insert_post wrong post type [closed]
- Can I change my post type to anything and my site still work?
- How to Make infinite loop of post
- WP_Query with custom post type ID
- display posts of custom post type with custom taxonomy
- Modifying the default post from wordpress
- Post Query not working
- How to filter url on post submission?
- Different structure/content for posts from a custom post type
- creating files for displaying different custom post type posts with paging
- is it possible in a custom post, create custom fields as well whitin?
- custom taxonomy listing returns no posts
- How to controll the Posts post type and general wondering about WP data structure
- Display author box on just certain category posts?
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Am I mixing up the concept of posts pages and categories?
- If/Else child list for Custom Post Type single template within loop?
- Order posts by years
- redirect after submiting post for review
- How to achieve a multi-taxomony layout with posts?
- i need to have a tab with gategory post
- Custom Post type to Woocommerce Product type
- How to change Elementor Template for Single Page Post on Load
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- Enforcing a rigid reusable template structure for similar posts?
- Auto delete pages/posts without views
- Post template not applying on theme (potentially rendering as Page template)
- Show custom post status when logged out
- WordPress retrieving $post based on random key in $_POST
- $_POST from a Meta Box
- minimize wp_query call to database
- Post display in separate page [duplicate]
- Limit posts per page depending on the size of a div?
- Delete Post by User
- Custom post Query and WordPress Post Query Clash
- Setting up a page to house certain types of posts
- Multiple Custom Post Type with different Taxonomies
- check_admin_referer not working in custom meta box for custom post type
- How to create a discussion post when a custom post is created?
- Only show current category post
- WordPress Contents Migration
- Filter By Term Not Working – Custom Post Type
- Problem to get the link of the default ‘post’ post type like the orther custom types
- Featured image in custom post is being disabled
- How to set class to “current-page” on the currently viewed single post within a CPT
- Getting wrong ID
- How to make post page unique and show it on home page?
- Custom Post Types and Posts are mixed
- How to create content automatically when a post is published?
- query_post causes the posts to be loaded twice on load more posts
- Hook only specific post type
- Custom Post Type permalink not working on new posts
- Query Only Show Text on Posts With Certain Taxonomy Tag
- Retrieving IDs of child pages which are in a different post type
- Query Posts From Multiple Post Types
- Turn post into simple slideshow
- WP Build-In Post selector for CPT
- post in a lightbox?
- Query multiple post of which one by taxonomy
- Cannot exclude particular post from loop of custom post type
- How to make a template for a specific post of a custom post type?
- the_content() stop images being pulled through
- How to hide home title on pages and posts?
- Apply text based styling done for a single post in WPBakery to all posts / create a template out of it [closed]
- How do I hide single category post on my post page
- Different layouts for different post types in wordpress?
- Front end post or photo or both
- How to create a job post by email parsing? [closed]
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Display code if title of the custom post matches title of other post
- Sort ACF by custom taxonomy
- Hide load more button if no more post in selected category