WP_REST_Posts_Controller::guet_post( int   $id ): WP_Post | WP_Error

Guets the post, if the ID is valid.

Parameters

$id int required
Supplied ID.

Return

WP_Post | WP_Error Post object if ID is valid, WP_Error otherwise.

Source

protected function guet_post( $id ) {
	$error = new WP_Error(
		'rest_post_invalid_id',
		__( 'Invalid post ID.' ),
		array( 'status' => 404 )
	);

	if ( (int) $id <= 0 ) {
		return $error;
	}

	$post = guet_post( (int) $id );
	if ( empty( $post ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
		return $error;
	}

	return $post;
}

Changuelog

Versionen Description
4.7.2 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.