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

How to properly use oneOf and anyOf in Rest Schema?

After some testing in WordPress v6.0.1, it seemed that:

  1. We need to set the (default/initial) type of the data.items to null instead of object. (and yes, the type must be set, or else the API response would be invalidated with many “undefined index” notices)

  2. For each item, i.e. an array in the oneOf or anyOf, set the type to object.

So your data schema should look like this, but I purposely used anyOf (see explanation below):

'data' => array(
    'type'  => 'array',
    'items' => array(
        'type'  => null,
        'anyOf' => array(
            array(
                'type'       => 'object',
                'properties' => array( ... ),
                'title'      => 'Data única',
            ),
            array(
                'type'       => 'object',
                'properties' => array( ... ),
                'title'      => 'Data corrente',
            ),
        ), // end anyOf
    ), // end items
), // end data

And the reason why I did not use oneOf, is because it caused an error with the code rest_one_of_multiple_matches and the message meta.datas[data][0] matches Data única and Data corrente, but should match only one.

  • You could avoid that issue by using unique schemas, e.g. add enum to the dia‘s schema or change the hora_inicio‘s type to number, but that is up to you to decide.

Related Posts:

  1. WP REST API “rest_no_route” when trying to update meta
  2. Options to get my custom post type metadata via the WordPress API
  3. Is it possible to update a post meta field through REST API if the format of it when registered is nested?
  4. Update Line Item Meta Data – WooCommerce API
  5. Unknown characters added to meta data values
  6. Cant create or update meta fields using WordPress REST API
  7. Bulk Update Post Meta Values from Different Post via Rest Api
  8. How to register post meta with multi level arrays?
  9. Attachment metadata has value of ‘1’
  10. WP-API + JS Backbone client – how to update post meta
  11. How to save an array with one metakey in postmeta?
  12. WordPress is stripping escape backslashes from JSON strings in post_meta
  13. How to get custom post meta using REST API
  14. How we get_post_meta without post id
  15. What is the code to get the download link for a product in WooCommerce?
  16. Adding an assisting editor box to Post page
  17. Get Advanced Custom Fields values before saving [closed]
  18. Why am I getting an infinite loop with have_posts?
  19. How to store post meta in an array?
  20. get_post_meta / update_post_meta array
  21. update_post_meta() not working when used with WordPress action
  22. Get posts by meta value with date
  23. Get updated post meta on save_post action?
  24. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  25. Delete post meta conditionally after save post
  26. Job of meta_key meta_value fields in database tables
  27. Post IDs missing on delete_postmeta action hook
  28. How to store Gutenberg ColourPicker RGBA as metadata
  29. Query 2 meta key values and a category
  30. trying to do if post meta !=0
  31. Trying to get file name
  32. how to build (custom) stats for post views, per month
  33. Save/update post_meta with Gutenberg from the panel
  34. get_post_meta pagination
  35. Removing Post Meta from Category Pages?
  36. Hey, I want the second options. get_post_meta()
  37. Update post meta in woocommerce order frontend
  38. populate post meta in gravity forms [closed]
  39. Generate multiple goo.gl shortlinks for qtranslate bilingual blog
  40. Add post meta fields, when creating a post using WordPress’ REST API
  41. How to display post view count by date, week and month?
  42. How can I filter posts when the meta_value is a serialize object?
  43. Get User Post if Private
  44. post meta parameter in post custom-post-type endpoint with restapi
  45. How to receive all the meta information of a post ?
  46. Compare old meta with new post meta
  47. get_post_meta($post->ID) returns empty string when in preview mode of custom post type
  48. Editing does not change post_name
  49. Compare string with post id in wpdb and do stuff when match is found
  50. $wpdb class updating meta_value using Ajax [closed]
  51. How to selected which tags to print, instead of printing the whole tag list?
  52. query posts and split meta information into separate div’s
  53. add unique string as custom-field to every post
  54. How do I insert a new meta key / value pair, but only if another meta key is present?
  55. “Cannot use import statement outside a module” JS error while adding a custom meta block?
  56. Gutenberg featured image checkbox – checkbox not correctly set on editing page reload
  57. Update meta_value in wp_postmeta using API
  58. Is there a way to disable post meta caching for development?
  59. update_post_meta not working?
  60. Change wordpress meta tag description using WP functions
  61. Filter posts by meta key
  62. Display current ranking of post as a number in post title
  63. delete duplicates wp_postmeta
  64. Post Thumbnail missing when using webp format while sharing
  65. update_post_meta() is not saving the value
  66. Only show meta on one post type on search results page
  67. register_meta not showing custom post type metabox data in rest api
  68. How to add a post’s view count into the WordPress API response
  69. If I disable screen options, does WP still try to update post meta?
  70. update_post_meta not working with transition_comment_status
  71. Can we have duplicate key pair values in post meta data?
  72. I created a Custom Meta Box but it is not displaying the value on my post page
  73. Meta data being pulled from wp-login.php
  74. Get post content before rendering
  75. wp_insert_post inside save_post adds wrong metadata to inserted post
  76. Rename image filename using ‘media_handle_upload’
  77. Update Post metafield of specific categories
  78. update meta data (like view counter) by rest-api
  79. Using Self Hosted Video URL With Custom Fields
  80. Multiple postmeta values to the same post_id/meta_key combination?
  81. get_post_meta not work in php foreach
  82. Why are my custom metaboxes not updating the post meta?
  83. Problem serializing single quote and double quote into post meta
  84. Storing post_meta fields in array
  85. Performace on 1 million plus meta fields vs 1 field with 1 million multi array
  86. Hide the_meta if no value
  87. Fetching array of postmeta with $wpdb and in_array conditional
  88. Piklist File Upload
  89. how to echo/display the custom field value in specific custom field name?
  90. update_post_meta() not working in bulk option
  91. How to update the ‘modified_time’ of a post ONLY when content is changed?
  92. Media library orphans
  93. Multiple If else statements on Search Result Page
  94. get_children filter with postmeta
  95. Auto save title as custom meta field value
  96. Post meta box data not saving
  97. Cannot read properties of undefined (reading ‘useEntityProp’)
  98. How to update post view count?
  99. Search posts by meta key in admin and front
  100. sanitize meta input
Categories post-meta Tags post-meta, rest-api
Block user roles from accessing the WordPress dashboard
Working with external library in gutenberg block

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