are you looking for get_post_type
?
You can use it to get any CPT type by slug and use it conditionally
For instance:
function filter_the_content( $content ) {
if ( ! is_user_logged_in() && 'my_cpt' == get_post_type() ) {
return "Content reserved to logged in users";
}
return $content;
}
add_filter( 'the_content', 'filter_the_content' );
The docs:
https://developer.wordpress.org/reference/functions/get_post_type/
Related Posts:
- Where to put my code: plugin or functions.php?
- Mini-Site Strategy
- How to set a fall back template for a custom post type in a plugin?
- Where to put archive-{post-type}.php
- need advice on how to do a lists using custom post types – taxonomy vs postmeta
- How to Get Current Custom Post Type Selected Taxonomy Term (Not All Terms)
- custom comments form for custom post type
- How to Use Custom Meta Field Instead of CPT Title in Post URL
- Not Able to Add New Class To CPT Attachment Image
- Custom post category name showing empty
- How to store the third party script with HTML code in the wordpress custom input field?
- Get next and prev item from custom WP_Query and Custom Post Type
- Error 404 change permalink term custom term taxonomy
- I have a random letter appearing before my content. Where to start looking for the cause?
- Having issue on Loading Meta Data From CSV to CPT
- Front End users account with lots of user Roles (not Woocommerce)
- Custom post type that lets users create a set of posts?
- call a function when insert and update a custom post type
- Not Able to Get Custom Post Type in Single and Single-custom-post-type
- How to develop custom URL redirection
- Issue on Counting CPT’s Under Taxonomy Term
- Not Able to Display Metabox Saved Checkbox and Selected option After Save/ Update
- Need some hints for my own WP theme development
- How to display value of custom fields in page
- Custom post type single-{custom}.php not working
- Where, When, & How to Properly Flush Rewrite Rules Within the Scope of a Plugin?
- Custom Post Type Plugin: Where Do I Put The Template?
- Creating a Custom Post Type as a Plugin? Why?
- How can I fix those issues generated by the Themecheck plugin
- Why is get_post_format() for “Standard” returns empty
- Custom Post Type Archive URL takes over page URL
- Password-protect a custom rss feed
- Unable to filter on field on edit.php page
- Custom Taxonomy and tax_query Issue?
- How to Build a Movie Library in WordPress 3.x
- template_redirect not working, apparently for no reason
- Custom role capabilities to administrator not taking effect (no plugin)
- Hierarchical or Non-hierarchical Custom Post Type in Real World Example
- How to append element after thumbnail
- ACF simple text field value not showing
- Detect where custom post type is declared
- get_object_taxonomies() returns empty array for custom post type
- Adding a custom post type taxonomy template in plugin
- Plugin: register custom post types, child ready and performance best practices
- Add custom ID to CPT posts only create not update
- Add custom post type as submenu [closed]
- Unable to get Custom Plugin Options data
- Display a grid of taxonomy terms at root taxonomy page
- What is the best practice for displaying my plugin content in themes?
- How to have this permalink structure: post_type/postname/custom_inner_page
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- When should I create custom post types?
- Custom post type’s extra fields – how to handle?
- Main query not querying any posts in custom taxonomy template
- Custom WP_Query doesn’t display all posts
- What’s an efficient way to change the post status of many posts at once?
- Two column layout with alphabetical ordering
- How exclude or skip post type with get_next_post_link
- Show Taxonomies with admin area for custom post type?
- Pagination doesnt work in custom post type
- How to add and display custom content that is not a post
- Types plugin custom post add_action hooks
- How to display posts from a certain category in a bootstrap 5 carousel loop with multiple items?
- Auto update publish date of CPT Post if default post custom field value match to cpt post CF Value
- Orderby custom fields is not working
- How to stop the custom post type URL from the google search?
- URL issue retrieving Custom Post Types using Backbone JS API
- Manually adding current_page_parent to wp_list_pages()
- WordPress Custom Post Loop
- Changing CPT permalink
- Get all posts by many custom post types
- programmatically generated custom post type is created more than once
- Add extra elements to the_post in a custom post_type
- Visualize info in just custom post_type in theme
- cpt not display inside nav menu
- Issue on Getting URL of Uploaded Image to a Custom Post Type
- Custom Post Type has wrong label and is not found when called by a loop
- Warning , Use of undefined constant PLUGIN_PATH?
- Show Post columns to specific users on condition
- Custom Post Type archive page listing a 404 or single post
- Too many revision when post status is changes [duplicate]
- Error when moving custom post type to bin
- Admin metabox with custom post type dropdown option not update choosed input after saving
- custom data model – link and populate from admin backend
- php output of generated custom metabox
- creating a custom post template
- 2 custom posts types, in their own columns, one pagination for both
- Can’t save custom post type fields
- Custom post type with custom taxonomy permalinks
- Shortcode error
- Having some trouble properly displaying Custom Post Types in templates
- Get term_id for each instance of custom taxonomy
- How to internationalize the sub menu name “categories” in Custom post type?
- Creating a Custom Post Type as a Plugin? Why?
- WordPress Roles
- WordPress search results grouped by post type
- How to change post cpt with submit button?
- How to separate posts by categories?
- Make term slugs of custom taxonomy available in WP REST API for custom post type?