WordPress at a glance
function is not described

WP_Post::get_instance() WP 3.5.0

Retrieve WP_Post instance.

This is a method of the class: WP_Post

No Hooks.

Return

WP_Post/false. Post object, false otherwise.

Usage

$var = WP_Post::get_instance( $post_id );
$post_id(int) (required)
Post ID.

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 3.5.0 Introduced.

Code of WP Post::get instance: wp-includes/class-wp-post.php WP 5.2.4

<?php
public static function get_instance( $post_id ) {
	global $wpdb;

	$post_id = (int) $post_id;
	if ( ! $post_id ) {
		return false;
	}

	$_post = wp_cache_get( $post_id, 'posts' );

	if ( ! $_post ) {
		$_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) );

		if ( ! $_post ) {
			return false;
		}

		$_post = sanitize_post( $_post, 'raw' );
		wp_cache_add( $_post->ID, $_post, 'posts' );
	} elseif ( empty( $_post->filter ) ) {
		$_post = sanitize_post( $_post, 'raw' );
	}

	return new WP_Post( $_post );
}