For the frontend, you can use template_redirect
action to identify the page, and perform redirects or adjust the request on the fly (untested):
add_action( 'template_redirect', static function () {
if ( ! is_singular( 'cpt' ) && ! is_post_type_archive( 'cpt' ) ) {
return;
}
if ( current_user_can( 'read_private_pages' ) || current_user_can( 'read_private_posts' ) ) {
return;
}
global $wp_query;
$wp_query->set_404();
status_header( 404 );
nocache_headers();
} );
For excluding from search, you’ll have to use pre_get_posts
to prevent the posts form being listed in the results, unless you change exclude_from_search
to true
in the CPT registration.
Related Posts:
- Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?
- Loading External Scripts in Admin but ONLY for a Specific Post Type?
- How to add custom columns to Custom Post Type admin screen
- Is it OK to move admin menu items?
- How to Change the Title of a Meta Box on a Specified Custom Post Type? [duplicate]
- Sort custom post types by last name in the backend
- How to add post_author column to custom post type
- WordPress User Roles, Custom Post Types, and Admin views
- How to customize admin posts based on the user who is logged in
- Remove rows in the manage post/page view
- Selecting a post in Dashboard
- Custom admin post.php page
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- How can I put content before my custom post type default pages?
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- How to hide private posts even if user is admin
- Change the text on the Publish button
- Load a script just to custom post type in admin
- Row actions for custom post types?
- Register CPTs using Dashicons for admin menu icon in WP 3.8
- Customize Edit Post screen for Custom Post Types?
- Filter by custom field in custom post type on admin page
- How can I remove the “Add New” button in my custom post type?
- Showing User’s Post Counts by Custom Post Type in the Admin’s User List?
- Merge two custom post types into one admin page?
- Remove the “View” Link in Post Admin
- Multiple custom post types under one admin menu
- Remove “posts” from admin but show a custom post
- How can I change the admin search posts fields?
- Prevent pre_get_posts filter on specific post type
- Custom post type: Add “Edit | Quick Edit | Trash | View” links to date (if title is not shown in column)?
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Add “Last Edited by” column to custom post type list table
- Add content in custom post type page after the title and before columns
- Change the edit page for a custom post type?
- How can I filter posts by post_parent in the admin?
- $query->set in pre_get_posts is unintentionally affecting the backend
- How to check if I’m on a custom post type archive in the admin area
- Admin Filter – Add Post Type Description on Post Type Page
- Filter custom post types in admin not working
- how to group custom post types
- How do I filter the excerpt metabox description in admin?
- Custom post type admin search
- Ordering posts by custom taxonomy in admin area
- Create a dropdown with Custom Post Types as option in admin
- How to put custom post types on front page
- How to Make an admin_notices Message That Disappears Once the User Leaves That Particular Page?
- Filter admin columns by custom post field value
- Hide/Show only specific categories in wp-admin new-post.php
- Best way to filter featured image text for a custom post type?
- Add Custom Post Type to Current Query
- WordPress Custom Post Type Admin Page really slow
- How to show more posts on an archive page?
- Add content before/after admin post wp-list-table
- Include post id[s] into WP_Query()
- Pre get posts for single post
- Custom post type Admin Page
- Prevent reload confirmation after AJAX save
- Filter by custom Field for Custom post type Admin Listing
- jQuery UI in Admin (Best Practice?)
- Post slug changed using code doesn’t reflect on editor when post is published
- Admin Post Update Redirection to Posts Screen
- Filtering Posts by Multiple Taxonomy Terms such as in an Admin Post Listing?
- WP Admin default view mode for Custom Post Type
- Exclude add_filter from the admin
- How to get my Custom Post Type to display in Recent Posts using “pre_get_posts”
- Renaming Menu Item within Admin Menu Section for a Custom Post Type?
- Remove date and category filters when editing custom post types
- Custom Post type sort order not working in the admin area
- Ordering Post 2 Post admin meta box by meta from CPT
- Pre_get_posts Gives 404 on Custom Post Type
- Custom admin columns for ALL custom post types
- How to get search results in the backend admin on a custom post type?
- Custom Metabox with Taxonomy Dropdown – Saving Issue
- filter search result with custom post type meta key
- how to create my own edit.php admin page code or template for my custom post type
- Order posts by (hierarchical custom) taxonomy terms and term children
- Meta Query “IN” doesn’t work with ACF checkbox filter
- Displaying Post Title on Post Edit page?
- Add custom column to custom post type overview in backend
- How Do I Use WP_Query to Run This Database Query as Search Result?
- Backend search; include CPT meta?
- Limiting number of custom posts shown on taxonomy page
- Include custom post type in “all posts”
- How to programatically set the post title of a CPT on wp-admin
- Unable to filter on field on edit.php page
- Can’t sort order of wp_query with 2 meta keys
- Make a custom column sortable, by custom post count
- Displaying custom post type on category pages but not on blog listings
- Using multiple instances of wp_editor in Custom Post Type admin area
- No results searching custom post type in admin panel
- Custom post type with tags
- How i add new link after Edit | Quick Edit | Trash | View in quick edit section
- Custom Post Type Name Causing Problem
- Adding help information to custom post edit page
- Only Show an Author Their Custom Post Types
- pre get posts changing the query
- Use a textarea for a custom post type
- Actions that Run on Admin Edit Page Load After Posts Are Queried
- Custom Post Type and taxonomies’s labels localization not working