Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get post


Takes a post ID and returns the database record for that post. You can specify, by means of the $output parameter, how you would like the results returned.


<?php get_post$id$output$filter ); ?> 


(integer or object) (optional) The ID of the post you'd like to fetch, or an object that specifies the post. By default the current post is fetched.
Default: null
(string) (optional) How you'd like the result.
  • OBJECT - (default) returns a WP_Post object
  • ARRAY_A - Returns an associative array of field names to values
  • ARRAY_N - returns a numeric array of field values
Default: OBJECT
(string) (optional) Filter the post. See sanitize_post_field() for a full list of values.
  • raw - (default)
Default: raw

Return Values

Returns a WP_Post object, or null if the post doesnt exist or an error occurred.


To get the title for a post with ID 7:

$title $post_7->post_title;

Alternatively, specify the $output parameter:

$title $post_7['post_title'];


Before version 3.5, the first parameter $post was required to be a variable. For example, get_post(7) would cause a fatal error.

Source File

get_post() is located in wp-includes/post.php and wp-includes/class-wp-atom-server.php.

Change Log

  • Since 1.5.1
  • 3.5.0 - the $post parameter is no longer passed by reference.


See also index of Function Reference and index of Template Tags.
This article is marked as in need of editing. You can help Codex by editing it.