WPDev.one

get_post()

get_post( mixed $post = null, mixed $output = OBJECT, mixed $filter = 'raw' )

Retrieves post data given a post ID or post object.

Parameters 3 required

Name / Type Description
mixed

(int | WP_Post | null) $post Optional. Post ID or post object. `null`, `false`, `0` and other PHP falsey values return the current global post inside the loop. A numerically valid post ID that points to a non-existent post returns `null`. Defaults to global $post.

Required
string

$output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.

Required
string

$filter Optional. Type of filter to apply. Accepts 'raw', 'edit', 'db', or 'display'. Default 'raw'.

Required

Return Value

((WP_Post)
(WP_Post | array | null) Type corresponding to $output on success or null on failure. When $output is OBJECT, a `WP_Post` instance is returned.

Function Information

Since Version
1.5.1
Source File
wp-includes/post.php
Advertisement