Skip to main content
WordPress made easy with the drag & drop Total WordPress Theme!Learn More

Show WordPress Page Content & Title By ID With Get_Post

Last updated on:

WordPress PageThe other day someone was asking my how to query a specific page in their WordPress theme so they could show it in the content in their site’s footer. Most the time when working with themes you most probably never query pages but more like your themes revolve around posts or custom post types, in which case you most likely use the get_posts, wp_query or the query_posts function.

To show the content of a specific page with using just the ID you’ll most likely have to use the get_post function which returns the database record for that post/page. And using the function is quite simple. Below I’ve pasted a quick snippet of a simple get_post query which you can alter to fit your needs.

<?php
$my_page_id = 69; //your page or post ID
$my_page = get_post($my_page_id); //retrieves the page via the ID
$content = $my_page->post_content; //gets the unfiltered page content
$content = apply_filters('the_content', $content); //cleanup content
$content = str_replace(']]>', ']]&gt;', $content); //cleanup content
$title = $my_page->post_title; //retrieves page title and sets the variable
?>

<?php
echo $title; //show page title
echo $content; //show page content
?>
Subscribe to the Newsletter

Get our latest news, tutorials, guides, tips & deals delivered to your inbox.

Comments

No comments yet. Why don't you kick off the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

Learn how your comment data is processed by viewing our privacy policy here.