I haven’t tested your code, but here the $object
is an object and not array:
// Here, $object is a WP_Post object.
function slug_update_post_meta_cb( $value, $object, $field_name ) {
return update_post_meta( $object->ID, $field_name, $value );
}
And you can actually use register_meta()
with a custom post type:
register_meta( 'post', 'myfield', [
'object_subtype' => 'custom_type', // Limit to a post type.
'type' => 'string',
'description' => 'My Field',
'single' => true,
'show_in_rest' => true,
] );
Check my answer here for more details.
Related Posts:
- How to add custom fields to admin UI and REST API response?
- Custom search with Custom Fields in WP REST API?
- Cannot add custom field to “orderby” parameter in Rest API
- Callback to custom field is not working in WordPress REST API
- filter custom post in rest api with custom function
- Custom REST endpoints for a custom post type with custom fields
- How to make an API call to a custom post type but filtering by meta value?
- How To Read Read Custom Post Type Data in Headless CMS Mode
- 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
- filter rest api post by a acf filed
- How to properly set a value to meta fields of a custom post type in WP-API/node-wpapi REST API?
- querying to custom field over ACF REST API
- How do I set the default admin sort order for a custom post type to a custom column?
- How can I change the admin search posts fields?
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- WordPress 4.4+ : How to revision CPT + metadata
- Query custom post type by custom field
- Filter a custom field based on selection of another custom field (ACF) [closed]
- How to get custom metabox image field?
- Using custom field as custom post title
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- Custom field being erased after autosave
- How to select one major category (or custom taxonomy) for a custom post type?
- front end radio custom taxonomy with custom post type
- How to get source of custom meta image?
- Add Taxonomy Values Within a Custom Post Type RSS Feed
- delete custom post based on custom field date
- Displaying Meta Box Image
- Get_post_meta() won’t return value
- Having trouble with custom date field for CPT query (WordPress)
- How to retrieve custom field types for all posts in WordPress/PHP?
- Display posts if a custom field value is equal to another custom field value
- Custom field default value with counter
- wp parse_query not working with custom meta value
- Recommended way to remove WP REST API returned data for custom post
- How to use custom fields to enable sticky posts on custom post types?
- Custom meta fields for specific custom type only
- Custom Fields vs Separate Table
- Check if a specific custom field exists?
- WordPress Create Post from front-end
- How to insert content from another Custom Post type into Post?
- Using several custom fields as custom post title
- Copy custom field value to post title
- Custom Post Type + 20k posts = blank/404 within Admin edit.php [duplicate]
- WP_Query orderby modified to include custom meta changes
- How to bulk copy custom fields between custom posts?
- Calculate all custom field values in the post loop
- add custom field to custom post type
- Get image post ID in media upload
- Role scoping for contributors down to the field level
- Having unique constraints for custom fields in a custom post type
- Display custom fields from custom posts in RSS feed
- Can we create a custom post template for a specific page template
- Settings API – save multiple tabs at once
- Send a conditional email notification when a custom field value changes in Post Type
- WordPress API for custom post types returns rest_no_route
- Submitting Custom Post Types with custom fields from Front-end form
- post_per_page ignored in WP_Query
- Sort custom post type by most current date picker
- Should Custom post types and fields be in the theme files or in a custom plugin packed into the theme?
- Remove default WYSIWYG editor without removing custom fields editors
- Display custom post type for specific user
- Display custom meta on page that has been check in custom post type
- How do I update_post_meta() or add_post_meta() with an AJAX call
- Filtering Custom Post Type by Comparing Date and Two Meta Keys
- How to prevent meta data from being edited in a post?
- Automatically add a character to field in edit post page
- Change Post Meta via AJAX from the posts list table
- Saving metabox keys and storing values as array
- Mandatory field in Custom post
- How to store the third party script with HTML code in the wordpress custom input field?
- WP Query from two Custom Post type fields as statement
- Filter custom post type admin list by custom meta column, where the column is another custom posts meta value
- How to display custom field in product description?
- when looping through custom post data not appearing
- Add custom template ‘sub-page’ to Custom Post type?
- Where is get_post_meta value located?
- Adding a Section for Visitors
- Automatic Set Category For A Custom Post Type
- Sort loop by custom field from different post type
- Meta_query by date for Events archive
- WordPress loop, show only one post per custom field
- Generate slug and meta data if meta field is empty
- one get_posts to return a number of custom posts for each meta value
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- Custom Post Type as invoice or order template
- WP_Query get posts where post_name is empty
- Get result from Custom Field in Custom Post type
- Make each Value of custom field show related posts when clicked
- Advanced search form with filters for custom taxonomies and custom fields
- Creating entries with image attachements within posts and managing them in a list
- How to Create a Frontend Html-list Editable in the Backend?
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- How to get lowest price from custom fields of posts
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- WordPress custom field sorting, weird behavior: the latest post is at the end
- I want to understand plugin implementation of custom posts / taxonomies / metaboxes
- How to consume external API from WordPress post editor and display the response data in the custom field?