[wp-trac] [WordPress Trac] #55365: Register meta field to attachment, but use media in REST API (was: meta field in media via REST API)

WordPress Trac noreply at wordpress.org
Sat Sep 3 19:10:59 UTC 2022


#55365: Register meta field to attachment, but use media in REST API
--------------------------+-----------------------------------------
 Reporter:  millerf01     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  REST API      |     Version:
 Severity:  normal        |  Resolution:  worksforme
 Keywords:  close         |     Focuses:  javascript, docs, rest-api
--------------------------+-----------------------------------------
Changes (by anna.bansaghi):

 * keywords:   => close
 * status:  new => closed
 * resolution:   => worksforme


Comment:

 Hi @millerf01, welcome back and thank you for the ticket!

 You were almost there, just mismatched the post types: need to use
 `attachment` instead of `media`.
 The `apiFetch(...)` request is correct, only `meta_key` registration needs
 some polish.

 There are two options for that:
 {{{#!php
 <?php
 register_meta( 'post', 'some_data', array(
         'object_subtype' => 'attachment',
         'type'           => 'string',
         'description'    => 'Some data',
         'single'         => true,
         'show_in_rest'   => true
 ) );
 }}}


 or

 {{{#!php
 <?php
 register_post_meta( 'attachment', 'some_data', array(
         'type'         => 'string',
         'description'  => 'Some data',
         'single'       => true,
         'show_in_rest' => true
 ) );
 }}}

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


More information about the wp-trac mailing list