This page redirects to an external site: https://developer.wordpress.org/reference/functions/get_post/
Languages: English • Italiano • post 日本語 Русский • Türkçe • (Add your language)
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 ); ?>
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:
<?php
$post_7 = get_post(7);
$title = $post_7->post_title;
?>
Alternatively, specify the $output parameter:
<?php
$post_7 = get_post(7, ARRAY_A);
$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.
get_post() is located in wp-includes/post.php and wp-includes/class-wp-atom-server.php.