Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Saving custom post types post_meta over REST-API fails

The register_meta() function is defined like so:

function register_meta( $object_type, $meta_key, $args, $deprecated = null )

And the $object_type (as of now) has to be post for all post types. So use this:

register_meta( 'post', 'survey_data', ... )

See the // {comments} in the code below, which I copied from here:

<?php
// The object type. For custom post types, this is 'post';
// for custom comment types, this is 'comment'. For user meta,
// this is 'user'.
$object_type="post";
$args1 = array( ... );
register_meta( $object_type, 'my_meta_key', $args1 );

UPDATE

If you’d like to limit the meta to a certain post type, use the object_subtype parameter like so: (that parameter was added in WordPress version 4.9.8)

// Add survey_data meta support to `survey` post type in REST API.
register_meta( 'post', 'survey_data', array(
  'show_in_rest'   => true,
  'object_subtype' => 'survey',
  ...
) );

// Add survey_data meta support to `my_cpt` post type in REST API.
register_meta( 'post', 'survey_data', array(
  'show_in_rest'   => true,
  'object_subtype' => 'my_cpt',
  ...
) );

And as you can see, just duplicate the same register_meta() call for other post types. But the $object_type needs to be post, even for Pages (page post type).

Related Posts:

  1. Update CPT meta data using REST API
  2. Rest Api v2 orderby meta_key in custom post type
  3. Getting meta in editor plugin, and event triggering issue
  4. post meta parameter in post custom-post-type endpoint with restapi
  5. WP API Response does not show my registered metadata
  6. How can I add a meta[] to my custom post type and search by term with the Rest API?
  7. rest_api_init is not getting invoked inside a Class
  8. Custom filter function not working with Custom post type
  9. Importing Data from a Non-WordPress database, into WP
  10. Getting thumbnails of a custom posts featured images in a page-templates metabox
  11. List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
  12. Remove Post Custom Meta Box
  13. Can’t publish custom post type – “You are not allowed to edit this post.”
  14. Custom fields for custom post type
  15. Show future events based on custom field AND order by date
  16. Meta Data for Custom Post Type not saving
  17. Using preg_replace to filter custom textarea
  18. Check if post with same meta value exists
  19. Filter date from post meta when date is in string format
  20. Get only used meta_values
  21. If Post Meta Equals Current Title Conditional Advanced Custom Fields
  22. Is there a way to exclude posts based on meta_values?
  23. How to add/edit advanced custom fields on custom post type’s WordPress REST API?
  24. Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
  25. How to get all post of custom post type by rest api?
  26. Create custom post with meta field with AJAX and the WordPress REST API
  27. Archieve.php not loading for custom post type
  28. WordPress API for custom post types returns rest_no_route
  29. Submitting Custom Post Types with custom fields from Front-end form
  30. create custom meta box with default value
  31. Get $post->ID from a URL
  32. Displaying a div from an assigned meta_value when on a page
  33. Meta data (Tags and Categories) for Custom Posts not showing.
  34. Display different information of a custom post type
  35. Create Array from custom post type to display a slider
  36. Setting Post Title via Meta Data returns Auto-draft
  37. How to Echo Metadata Value in Currency Format
  38. Issue on Working with Metabox – Checkbox to enable Sale Items
  39. Filter posts by tax (dropdown) and meta value
  40. delete_post_meta() for whole CPT / multiple posts?
  41. How to get specific post meta by title or id
  42. Publish and save specific postmeta to a filtered post_type
  43. How to move a post to different post type with all meta data?
  44. Why do I have to press the “Update” button twice to save my meta box values?
  45. How can I display a drop-down select of Post Names
  46. how to show records that don’t have custom meta value
  47. set_query_params using custom params defined in functions file?
  48. How to see posts in taxonomy endpoint
  49. How to detect that the save_post hook is calling the callback associated to the current edit post page only
  50. REST filters only firing when I have a param set
  51. $post->post_meta not pulling any post in wordpress/php
  52. Values from meta-box not on $_POST
  53. Custom REST endpoint not working to retrieve single posts (“rest_no_route”)
  54. WP_Query of custom post type sorted by meta_key has unexpected results
  55. How to add a filter to a custom post type to get adjacent custom posts via the REST API
  56. Returning a custom content types with meta values
  57. Custom post type suddenly stoped working after WordPress 5 update
  58. Batch Extract Date from post title and put into ACF custom field
  59. How to handle new post from API request?
  60. copy images from custom field to another custom field
  61. wp-json API: not logged in when clicking link to the API from admin mode
  62. How to show custom field on specific custom post type posts only when filled
  63. How to handle this specific case of custom post type?
  64. Custom Post Type API doesn’t show taxonomy or category array
  65. Save CTP post meta different values each day without overwriting previous values
  66. get_post_meta returns NULL in front-end, but correct result in back-end
  67. Cannot obtain custom meta information
  68. Problem with adding custom post type meta to header by plugin
  69. is_main_query() never called on WP 4.4
  70. How can I output WPAlchemy repeating fields meta values in my page template?
  71. Meta box data is saved but NOT displayed in the meta box text field. Why?
  72. How to call a post’s metadata in shortcode.php?
  73. Save Metabox Custom Field Value
  74. Echo custom post meta from options array
  75. Value of post meta dropdown is not showing in WordPress
  76. Meta box data not saving
  77. Get all metadata for a given custom post type
  78. WP_Meta_Query object with conditionals
  79. Trying to write shortcode with get_post_meta but isn’t working
  80. Related posts meta_query CPT
  81. Meta box with front-end styling
  82. Sanitaizing Select Optin For Custom Post Type Metabox in WP
  83. How can I get some of a posts meta data whilst it is still inserting?
  84. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  85. Advanced custom field – posted fields from custom post type
  86. Cannot Save MetaBox Data in Custom Post Type
  87. delete duplicate meta_value with same post_id
  88. HM CMB: Post Select Field for CPT ID
  89. Search CPT Title AND Meta
  90. Getting WordPress to store 0 values for custom post type meta
  91. updating one custom meta field only
  92. Add a class to post_class if more than one post shares same meta_value_num
  93. Function to return values from metabox
  94. Add a meta field to the list of results for a custom post type
  95. best way to use custom taxonomy, post type and meta in a job system
  96. Empty meta-box returns publishdate if no value is set?
  97. Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
  98. Building tags and archive using meta from custom post type
  99. How to order custom posts by one of the custom fields value, ‘date’?
  100. Problem Saving Custom Post Type Meta Values
Categories custom-post-types Tags custom-post-types, post-meta, rest-api
I can not change the background-color value of wp: meta_value of content.xml
Show all menu levels except top level. How to exclude top level of a menu?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress