WP_REST_Posts_Controller::get_post() protected WP 4.7.2
Get the post, if the ID is valid.
{} It's a method of the class: WP_REST_Posts_Controller{}
No Hooks.
Return
WP_Post/WP_Error. Post object if ID is valid, WP_Error otherwise.
Usage
// protected - for code of main (parent) or child class $result = $this->get_post( $id );
- $id(int) (required)
- Supplied ID.
Changelog
Since 4.7.2 | Introduced. |
Code of WP_REST_Posts_Controller::get_post() WP REST Posts Controller::get post WP 5.6
protected function get_post( $id ) {
$error = new WP_Error(
'rest_post_invalid_id',
__( 'Invalid post ID.' ),
array( 'status' => 404 )
);
if ( (int) $id <= 0 ) {
return $error;
}
$post = get_post( (int) $id );
if ( empty( $post ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
return $error;
}
return $post;
}