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
- Remove “posts” from admin but show a custom post
- Prevent pre_get_posts filter on specific post type
- Add content in custom post type page after the title and before columns
- How to check if I’m on a custom post type archive in the admin area
- How to put custom post types on front page
- Add content before/after admin post wp-list-table
- Custom post type Admin Page
- jQuery UI in Admin (Best Practice?)
- Filtering Posts by Multiple Taxonomy Terms such as in an Admin Post Listing?
- Custom admin columns for ALL custom post types
- how to create my own edit.php admin page code or template for my custom post type
- Backend search; include CPT meta?
- Adding help information to custom post edit page
- Custom Post Type and taxonomies’s labels localization not working
- How do I add a custom button to my “edit” list? ( edit.php?post_type= ) beside “Add New”
- Show admin help message across custom post type parent and child posts
- How to show custom (checkbox) field value in admin post list?
- Add text to post list/edit screens?
- Using pre_get_posts to Filter Posts
- Remove “Get Shortlink” button in admin of custom post type
- Custom post admin filtering by post meta (the date)
- Admin Column Text Positioning
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- Get all of user’s custom post types in WP Admin for plugin
- Using pre_get_posts to filter one loop in a multiloop archive
- How do increase the amount of links shown down the left in the admin menu?
- Change archive page template using pre_get_post
- How to avoid manage posts screen duplicates when two plugins use the same library
- Adding HTML tags or css classes to admin columns
- Create a page that will be used to create a custom post type
- Custom Post List View: Page or something else?
- A simple script to allow sorting of custom posts in admin?
- How to sort custom columns for custom post type without meta query and pre_get_posts?
- Filter term taxonomy metabox in custom post type
- manage_edit-{post_type}_sortable_columns sorts, but wrong!
- Filtering posts list table
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Excluding a Custom Post Type with a specific tag using pre_get_posts
- Hide Status Option From WordPress Publish Metabox and Rename Published on:
- Insert Custom Post Types
- how to show records that don’t have custom meta value
- Custom Post Type – Support “author” only for admins
- Custom posts of one type have disappeared from admin. Still appear on site [closed]
- How to get the custom post list to admin user edit page?
- How to query for posts (hierarchical custom post type) that have children but are NOT top level?
- CPT Archive pre_get_posts not working?
- Custom Post Type – Portfolio no longer works
- Multiple wp_editor instances in custom post type using Ajax
- How to customize `Edit-Post` Screen
- Multiple custom post types on same admin page
- How to display author details in a custom post type in the wordpress backend?
- Add Content Column to Custom Post Type backend
- Change Text in Admin Panel
- get_posts() returns empty on custom post type /wp-admin/edit.php
- How to display an admin-notice after custom post type edit modification
- Is there any filter to add a custom attribute to the tag in admin panel?
- Sort custom post column by generated value?
- Limiting the Number of User Posts to Their Own Posts
- How to overwrite function to display parent page combobox for custom post type in Edit Post Page?
- Adding orderby url parameter to main CPT admin menu link
- Help Adding filter to Add Media button for custom post type
- How to override post-new.php with custom template
- Pagination in wp-admin for CPT
- Set different posts_per_page for custom post type/taxonomy
- Apply pre_get_posts to specific custom post type in the admin area
- Meta query broken since 4.7.4 Update
- Custom Post Type shows pagination (w/404) or posts_per_page query, but not both
- Custom Post Search
- Custom post type doesn’t display on admin list
- Shared Custom post type between WP network sites
- Custom Post Type Pagination Problem in Admin Section
- Admin menu post type
- WordPress Author Posts Review After Every Change In The Same WordPress Post
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- Filtering in admin broken for custom post type in 3.8.1?
- Custom post type won’t take my custom fields
- pre_get_posts action doesn’t work
- custom post types, pre_get_posts, wp_list_categories
- Admin menu link with variable
- Display box in sidebar of custom post type