[wp-trac] [WordPress Trac] #46264: Page attributes 'ORDER' does not saving data for post-type 'post'.

WordPress Trac noreply at wordpress.org
Thu Sep 19 13:30:15 UTC 2019


#46264: Page attributes 'ORDER' does not saving data for post-type 'post'.
--------------------------+------------------------------
 Reporter:  tanvirul      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Editor        |     Version:  5.0
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  rest-api
--------------------------+------------------------------
Changes (by websupporter):

 * keywords:  has-patch needs-unit-tests => has-patch
 * focuses:   => rest-api


Comment:

 Hi,
 I just stumbled upon the same problem. Thank you for reporting @tanvirul!

 I think the general idea of the fixed schema is the following: If you
 would generate those keys (menu_order, excerpt, etc) only dynamically, a
 lot of clients might break, as they might just assume every post object
 has an excerpt. The fixed schema ensures some stability for the core
 features the content types have.

 That said, it is still possible to extend the basic data concept
 (`register_rest_field()`), so the fixed schema does not mean its intended
 to serve only those data values.

 So while `remove_post_type_support()` should not remove properties from
 the JSON output, I think `add_post_type_support()` should add properties
 to it.

 I tried @felipeelia fix and it works as intended. Thank you for providing
 it. My last patch added a unit test for the intended behavior.

 In the meantime, this workaround helped me:

 {{{#!php
 <?php
 add_action(
     'rest_api_init',
     function() {
         register_rest_field(
             'post',
             'menu_order',
             [
                 'get_callback' => function(array $object) {
                     if (! isset($object['menu_order'])) {
                         return 0;
                     }
                     return (int) $object['menu_order'];
                 },
                 'schema' => [
                     'type' => 'integer',
                 ]
             ]
         );
     }
 );
 }}}

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


More information about the wp-trac mailing list