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

WordPress Trac noreply at wordpress.org
Sun Mar 22 06:10:33 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         |  Resolution:
 Keywords:  has-patch      |     Focuses:  rest-api
---------------------------+------------------------------
Description changed by sabernhardt:

Old description:

> 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.

New 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 ==

 [https://github.com/WordPress/wordpress-develop/blame/6.9.4/src/wp-
 includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L766-L769
 Lines 766-769 of class-wp-rest-posts-controller.php] access `$post->id`
 and `$post->post_parent` on a `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#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list