The REST API has no parameters, options to solve this – in my opinion. But you should register only if the users have the capability in his role, like the follow example.
add_action( 'rest_api_init', function() {
// Exit, if the logged in user have not enough rights.
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
// Register Meta Data.
register_meta( 'post', 'foo', array(
'show_in_rest' => true,
));
});
That’s fire the custom data in the REST API only, if the user have enough rights, capabilities in his role. My register_meta()
is only an example, that should also work with your additional parameter for register_post_type
, like $wp_post_types[ 'cpt' ]->show_in_rest = true;
.
Related Posts:
- With Rest V2 (WP4.7) how does one restrict certain RESTFUL verbs?
- REST API: How can I restrict a custom post type to only be accessible by authenticated users?
- Allow member to have access to custom post type only. Permission to only edit their own posts
- Update CPT meta data using REST API
- How do I Filter Custom Post Type by Custom Taxonomy in the newest WordPress RESTful API?
- WordPress REST Create Post of Custom Type
- WP Rest API Querying Custom Posts by ACF fields
- How to force Authentication on REST API for Password protected page using custom table and fetch() without Plugin
- How to get dynamically custom post type that are under a certain category
- Get the Category Name instead of ID from WP-API
- How to automatically apply a password to all posts within a custom post type
- create a back-end wordpress content submission using custom post type
- Rest Api v2 orderby meta_key in custom post type
- Get custom post type REST API not working
- Allow Users Access to Custom Post Type Only
- How to add custom fields to admin UI and REST API response?
- WordPress Rest API only returns content when posttype has editor capability
- Custom search with Custom Fields in WP REST API?
- Wp Rest API request posts from a custom taxonomy
- Recommended way to remove WP REST API returned data for custom post
- Making a Custom Post type only visible to non-users via a specific link
- Limit users by custom taxonomy and user roles
- Custom Post Type and API REST is not working
- Add custom post type to Backbone collections
- React post to WordPress custom post type
- Custom Post type with ACF in REST API, how do I get those values?
- is_main_query() not working for WP REST API
- Very simple wordpress block to display posts from an api call
- Add custom parameter to REST API request of a custom post type?
- Custom Taxonomy Invalid in REST API
- How do I get the intended post type of a revision post?
- Using The REST API How To Pull All Custom Posts?
- How to restrict CPT post’s fronted view only for specific user roles?
- Cannot add custom field to “orderby” parameter in Rest API
- Getting meta in editor plugin, and event triggering issue
- Expose a custom field of a custom post type to the REST API
- How to create custom post by using REST API securely?
- Custom post type archive page – Posts overview – with one modal for multiple posts?
- WP Rest API – How to get an empty response if query has no posts
- Callback to custom field is not working in WordPress REST API
- Custom Post Type not showing in Rest API on Multisite
- post meta parameter in post custom-post-type endpoint with restapi
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- filter custom post in rest api with custom function
- API Rest Custom Post Type doesn’t return all data
- Custom REST endpoints for a custom post type with custom fields
- Create custom post with custom user rules
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- How to get all post of custom post type by rest api?
- Create custom post with meta field with AJAX and the WordPress REST API
- WordPress API for custom post types returns rest_no_route
- Make (custom) post type accessible only by custom query
- Adding guestbook to my wordpress site
- Building Forums with Custom Post Types
- set_query_params using custom params defined in functions file?
- How to see posts in taxonomy endpoint
- WP API Response does not show my registered metadata
- REST filters only firing when I have a param set
- Custom REST endpoint not working to retrieve single posts (“rest_no_route”)
- How to add a filter to a custom post type to get adjacent custom posts via the REST API
- How to handle new post from API request?
- wp-json API: not logged in when clicking link to the API from admin mode
- How to handle this specific case of custom post type?
- Restrict category access to specific users/groups. Author always has access
- Custom Post Type API doesn’t show taxonomy or category array
- Post/Custom Post Type URL Access
- How to make an API call to a custom post type but filtering by meta value?
- Fetching custom post type without knowing post type (REST API)
- WordPress REST API V2: “{CUSTOM_POST_TYPE} matches Term ID List and Term ID Taxonomy Query, but should match only one.”
- no_rest_route in Unit Testing for REST endpoint for CPT registered via show_in_rest
- How can I create new CustomPostType record using wp.api.collections?
- Custom endpoint filtering post by custom taxonomies
- wp rest api orderby field in a custom table
- How To Read Read Custom Post Type Data in Headless CMS Mode
- WP_Query: how to search tags in addition to a custom post type?
- How can I sort the results of a REST API response by the title of a connected custom post type?
- How to filter a matched value with custom key using WP REST API?
- URL issue retrieving Custom Post Types using Backbone JS API
- How to add field to custom post type endpoint
- Create API’s for custom-post types & custom queries using REST or Graphql
- Action on Custom Post publish
- Get Custom Post types data from the API
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- register_rest_field update_callback don’t work for $_FILES
- localize_script or rest api
- Issue with CPT posts within WP REST API showing as []
- Saving custom post types post_meta over REST-API fails
- WP REST API Custom endpoint don’t work in my plugin
- filter rest api post by a acf filed
- How do you make a custom post type invisible for subscribers
- How to properly set a value to meta fields of a custom post type in WP-API/node-wpapi REST API?
- How to create new permission for custom post types for doing specific tasks
- How can I remove “Add new” button on custom post type
- Allowing logged in users to create custom posts
- Store custom post type with JSON content
- querying to custom field over ACF REST API
- Create settings page to enable or disable CPT
- Make term slugs of custom taxonomy available in WP REST API for custom post type?
- Custom post type REST api 404: Updating failed. No route was found matching the URL and request method
- upload image with rest API to the media library