Using WordPress ‘get_page()’ PHP function

The get_page() WordPress PHP function retrieves page data given a page ID or a page object. However, it’s recommended to use get_post() instead of get_page().


$page_data = get_page( $page, $output = OBJECT, $filter = 'raw' );



$page_data = get_page(42);

Returns a WP_Post object containing the data of the page with ID 42.


  • $page (int|WP_Post) – Required. Page object or page ID. Passed by reference.
  • $output (string) – 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.
  • $filter (string) – Optional. How the return value should be filtered. Accepts ‘raw’, ‘edit’, ‘db’, ‘display’. Default ‘raw’. Default: ‘raw’.

More information

See WordPress Developer Resources: get_page


Display a page’s title and content

$page_id = 42; // The ID of the page you want to display
$page = get_page($page_id);
$title = $page->post_title;
$content = $page->post_content;

echo '<h3>' . $title . '</h3>'; // Display the title wrapped in h3
echo $content; // Display the content

Display a page’s content as an associative array

$page_id = 42;
$page_data = get_page($page_id, ARRAY_A);
echo $page_data['post_content'];

Display a page’s content as a numeric array

$page_id = 42;
$page_data = get_page($page_id, ARRAY_N);
echo $page_data[4];

Display a page’s content with a ‘display’ filter

$page_id = 42;
$page_data = get_page($page_id, OBJECT, 'display');
echo $page_data->post_content;

Retrieve and display a page’s data using a WP_Post object

global $post;
$current_page = get_page($post);
echo $current_page->post_title . '<br>';
echo $current_page->post_content;