A simple filter on your post content can do this job easily. Lets try this code
function tp_stop_guestes( $content ) {
global $post;
if ( $post->post_type == 'YOUR_CUSTOM_POSTTYPE' ) {
if ( !is_user_logged_in() ) {
$content="Please login to view this post";
}
}
return $content;
}
add_filter( 'the_content', 'tp_stop_guestes' );
We are applying filter on the post content. If the post type is your custom post type and the user is not logged in, s/he will see “Please login to view this post” instead of original content.
Related Posts:
- Remove Custom Taxonomy Metabox from Custom Post Type Screen
- Get terms by taxonomy AND post_type
- How can I change the admin search posts fields?
- Creating conditional blocks for WordPress Gutenberg
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Change the edit page for a custom post type?
- Automatically create child pages when saving a (parent) page
- Featured Image Panel Missing From Custom Post Type in WordPress 3.2
- Is there a way to use regular categories with custom post types?
- Add Post type menu to another menu
- Getting Bootstrap accordion working in WordPress loop with custom post type (collapsing issue)
- “pagination” (but not really) and queries using custom posts types
- Best way to style first post differently?
- How to create user personal pages with information from their meta profile fields?
- Including two taxonomies in a permalink structure
- WP Rewrite Rules – Custom post type & taxonomy
- How to Sort by Date When Using d-m-Y Format
- where can I see my custom post type archive template?
- action init hook and get_post_types
- Website bookmarks as a custom post type
- Post Ancestor and Child Post in Custom Post Type
- Need idea: custom post type and custom meta
- grant a privilege for roles (for example editors) and higher
- Sort posts based on multiple custom fields
- Custom Post Order for a Custom Post Type
- How to make a custom taxonomy selectable in post publish area?
- How to Separate CPT From Regular Posts?
- Specify a Page as the parent to the CPT Archive
- Remove wrong dashes from get_the_title()
- Redirect page to first post in custom post type
- Hooking in to an archive page?
- Edit / delete custom post types through web page (not admin)
- Custom columns for multiple custom post types
- post_row_actions not working for hierarchical post type
- Custom Post Type / Two level deep taxonomy (cat. and subcat.) uri problem (error 404)
- Am I using the flush_rewrite_rules function in the right place?
- Tax query not producing any results
- How to make global post work with custom post type?
- How should I structure my post types?
- Post Quote with image on header for news site
- 301 redirect for converted post type
- Custom post types team data
- Team club with CPTs and user registration + user dashboard
- WordPress permalink / slug with numbers in the middle of the post name shows the broken page
- Custom post type editor with dynamic selects, one drop down populating a second second drop down not working
- Custom Post Type and Category Base Rewrite Issue
- Order a custom post type admin screen by a second custom post type title
- next_/previous_post_link() `in_same_category` appears to fail when true
- Add a ‘guide’ image to custom post type admin page
- Understanding Post Formats/Custom Post types Etc
- archive as a page, so that it can be added in the wp_menu_nav
- Displaying Custom Posts
- singular_name label in custom post type
- How to get dropdown instance value in WordPress custom Widget
- Different post title, keywords and description
- Trying to add a class to post links
- WordPress custom post categories and subcategories on category.php
- Can’t replace the default sidebar with a custom sidebar on Custom Post Type in Genesis
- Get Terms from Custom Taxonomy and Current Post
- Catch and display error on save_post action
- custom post archive URL is wrong
- How do I call the custom Post Type name and permanent link to my php file?
- Mandatory field in Custom post
- How to display related posts using the same taxonomy for custom types (WordPress, Pods, Woo)
- Filter custom post type admin list by custom meta column, where the column is another custom posts meta value
- In child theme, add CPT to custom taxonomy registered in parent theme
- How to display posts with plugin (advanced custom fields) field groups?
- Custom taxonomies not displaying in some custom posts
- Load info from customposttype into template page
- Is there a way to create a sidebar of bullets
- From CPT Custom Loop into Shortcode?
- Set a Default CPT taxonomy by taxonomy id
- Skip latest 3 posts from loop
- Custom taxonomy terms registered not showing when added in child theme
- How to redirect from wp-admin/edit.php to a frontend page for specific custom post type?
- How to assign post to category
- WordPress deletes custom posts instead of trash them
- Creating custom post type relationships
- How to create groups like that in buddypress?
- Display all Custom taxonomy terms and their relevant custom posts
- wordpress query_posts with foundation 6 Accordion not working correctly
- Include template if a post is a single product
- How to remove UI access to Custom Post Type using direct links?
- get_post_types doesn’t work in plugin
- Allow viewing the edit screen for a post type, but not make/save/publish/update changes
- Would like to add a “leaderboard” (custom field) to a custom post type
- Render custom taxonomy query as single template
- I have a custom post type that I want to query a dynamic category name from a custom meta field
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- adding a shortcode into a custom post type
- Custom Post within a custom post
- Custom My account page and custom page for editing posts
- What’s the best way to show custom post types? With page template it’s not perfect!
- show custom post types for a month
- Post count for particular term
- using a template for more then 1 page
- Add word limit in wordpress posts editor
- wordpress custom post type shows other cpt posts in admin menu
- Show custom category archive as front page and remove taxonomy slug from urls
- Meta_query question