[wp-trac] [WordPress Trac] #54484: REST API returns (empty) array for Meta but Schema has type object
WordPress Trac
noreply at wordpress.org
Tue Mar 10 15:39:26 UTC 2026
#54484: REST API returns (empty) array for Meta but Schema has type object
-----------------------------------------+-----------------------
Reporter: dtrunk90 | Owner: flixos90
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 7.0
Component: REST API | Version: 4.7
Severity: normal | Resolution:
Keywords: has-patch changes-requested | Focuses:
-----------------------------------------+-----------------------
Comment (by sajib1223):
== Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/10889
=== Environment
- WordPress: 7.0-beta1-61709-src
- PHP: 8.2.29
- Server: nginx/1.29.5
- Database: mysqli (Server: 8.4.8 / Client: mysqlnd 8.2.29)
- Browser: Firefox 148.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.4
- MU Plugins:
- test-trac-54484.php
- Plugins:
- Test Reports 1.2.1
=== Steps taken
1. Applied the PR diff on trunk using gh pr diff 10889 | git apply
2. Created an MU plugin that registers a custom post type book with
show_in_rest => true and custom-fields support, but no registered meta
fields
3. Created a sample book post (ID 7) via WP-CLI
4. Tested http://localhost:8889/wp-json/wp/v2/books/7?_fields=meta with
patch — returned {"meta":{}} (empty object)
5. Reverted the patch using git checkout
6. Tested the same URL without patch — returned {"meta":[]} (empty array,
the bug)
7. Re-applied the patch and ran PHPUnit tests:
WP_Test_REST_Post_Meta_Fields (151 tests, 581 assertions),
WP_Test_REST_Posts_Controller (278 tests, 2627 assertions), REST_Blocks
(17 tests, 26 assertions) — all passing
8. ✅ Patch is solving the problem
=== Expected result
- Empty meta field should return {} (JSON object) instead of [] (JSON
array), matching the REST API schema type definition of object
=== Additional Notes
- Default posts/pages have Gutenberg's footnotes meta registered, so their
meta is never truly empty. A custom post type with no registered meta is
needed to reproduce the bug.
- The patch also correctly handles the wp_pattern_sync_status meta in the
blocks controller for both array and object
types.
=== Support Content
MU Plugin used for testing (mu-plugins/test-trac-54484.php):
{{{#!php
<?php
add_action( 'init', function () {
register_post_type(
'book',
array(
'label' => 'Books',
'public' => true,
'show_in_rest' => true,
'rest_base' => 'books',
'supports' => array( 'title', 'editor', 'custom-fields' ),
)
);
});
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54484#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list