[wp-trac] [WordPress Trac] #55365: meta field in media via REST API

WordPress Trac noreply at wordpress.org
Thu Mar 10 19:41:53 UTC 2022


#55365: meta field in media via REST API
----------------------------------------+-----------------------------
 Reporter:  millerf01                   |      Owner:  (none)
     Type:  defect (bug)                |     Status:  new
 Priority:  normal                      |  Milestone:  Awaiting Review
Component:  REST API                    |    Version:
 Severity:  normal                      |   Keywords:
  Focuses:  javascript, docs, rest-api  |
----------------------------------------+-----------------------------
 Hi there,

 I found either a bug or a documentation issue.

 The codex https://developer.wordpress.org/rest-api/reference/media/ refers
 to a `meta` that is both editable and readable.

 I am writing a Gutenberg block and wanted to store data in the `meta`
 field. I am using:

 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!javascript
 apiFetch( {
                 path: '/wp/v2/media/' + mediaId,
                 method: 'POST',
                 data: {
                         title: title,
                         description: description,
                         meta: {
                              some_data: "some_value"
                         }
                 }
         } )
 }}}
 }}}

 However, it always returns an empty array as `meta`

 [[Image(https://imgur.com/a/8XcUJ5b)]]

 I also tried setting some custom field

 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!javascript

 register_meta( 'media', 'some_data', array(
         'type' => 'string',
         'description' => 'Some data',
         'single' => true,
         'show_in_rest' => true
 ) );
 }}}
 }}}

 I eventually tried  format the `meta` field I am sending

 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!javascript
 meta: [{
 some_data: "some_value"
 }]
 }}}
 }}}

 or

 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!javascript
 meta: [{
 key: "some_data",
 value: "some_value"
 }]
 }}}
 }}}

 But still nothing.

 Do you have any idea?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55365>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list