WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#43772 closed defect (bug) (duplicate)

Undefined property: WP_Error::$term_id in /var/www/html/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php on line 655

Reported by: mahnunchik Owned by:
Milestone: Priority: normal
Severity: major Version: 4.9.5
Component: REST API Keywords:
Focuses: Cc:

Description

I've faced with the following error while using wp-json/wp/v2/categories API

<b>Notice</b>:  Undefined property: WP_Error::$term_id in <b>/var/www/html/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</b> on line <b>655</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /var/www/html/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php:655) in <b>/var/www/html/web/wp/wp-includes/rest-api/class-wp-rest-server.php</b> on line <b>1248</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /var/www/html/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php:655) in <b>/var/www/html/web/wp/wp-includes/rest-api/class-wp-rest-server.php</b> on line <b>1248</b><br />

Change History (7)

#1 @mahnunchik
3 years ago

		if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) {
			$parent_term_id = 0;
			$parent_term    = get_term( (int) $request['parent'], $this->taxonomy );

			if ( $parent_term ) {
655->			$parent_term_id = $parent_term->term_id;
			}

			$prepared_term->parent = $parent_term_id;
		}

#2 @soulseekah
3 years ago

  • Keywords reporter-feedback added; needs-patch removed

Hey! Welcome to Trac!

What's the REST API call that you're performing to get this warning?
What's the setup on the categories like?

#3 @mahnunchik
3 years ago

I am performing POST request to /wp-json/wp/v2/categories with the data including name, description, slug, and parent (may be null).

#4 follow-up: @soulseekah
3 years ago

Does this still happen or did you figure things out?

#5 in reply to: ↑ 4 @mahnunchik
3 years ago

Replying to soulseekah:

Does this still happen or did you figure things out?

Yep, this still happen if parent is null.

#6 @TimothyBlynJacobs
2 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #44983.

I believe this was fixed in r44965

#7 @desrosj
2 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.