[wp-trac] [WordPress Trac] #64921: REST API POST /wp/v2/posts: Undefined property stdClass::$id (line 766)

WordPress Trac noreply at wordpress.org
Sat Mar 21 18:37:01 UTC 2026


#64921: REST API POST /wp/v2/posts: Undefined property stdClass::$id (line 766)
---------------------------+-----------------------------
 Reporter:  swissspaceboy  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  General        |    Version:  6.9.4
 Severity:  normal         |   Keywords:
  Focuses:  rest-api       |
---------------------------+-----------------------------
 Description:

 Creating posts via the standard WordPress REST API (POST /wp/v2/posts)
 generates PHP warnings in class-wp-rest-posts-controller.php.

 == Warnings ==

 {{{
 PHP Warning: Undefined property: stdClass::$id in
 wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line
 766
 PHP Warning: Undefined property: stdClass::$post_parent in
 wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line
 769
 }}}

 == Steps to reproduce ==

 Authenticate via Application Password (Basic Auth)
 Send POST /wp-json/wp/v2/posts with body: {"title": "Test", "content":
 "<p>Hello</p>", "status": "draft"}
 Post is created successfully, but warnings are logged
 == Environment ==

 WordPress 6.9.4
 PHP 8.3
 Apache / LiteSpeed
 == Confirmed on 3 independent installations ==

 Site A: WordPress + Polylang
 Site B: WordPress + Polylang
 Site C: WordPress only (no Polylang, no multilingual plugin)
 All 3 produce identical warnings, confirming this is a core issue.

 == Impact ==

 Post creation works — no functional breakage
 2 PHP warnings per REST API call pollute php-error.log
 Automated workflows creating multiple posts amplify the log noise
 == Analysis ==

 Lines 766-769 of class-wp-rest-posts-controller.php access $post->id and
 $post->post_parent on an stdClass object that lacks these properties. The
 $post object returned at this stage appears incomplete — possibly a
 regression in how prepare_item_for_response() receives the newly created
 post.

 == Expected behavior ==

 No PHP warnings when creating posts via REST API.

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


More information about the wp-trac mailing list