WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the following code, to output the content from a page with the id of two. This is in my custom template file which is selected in the page. It works fine locally but online it does not work, it outputs nothing, the id is based of this url http://www.goodmorningmoon.ca/wp-admin/post.php?post=2&action=edit What might I do to diagnose this problem.

<?php $my_query = new WP_Query('page_id=2'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
share|improve this question
Did you replicate the database for each instance with dump or manually? – perpetualstudent Mar 18 '12 at 23:45
I didn't replicate the database, I just added the same content to the page. – Anders Kitson Mar 18 '12 at 23:48
So you've got two different versions of your site, one locally and one online, and each uses a different database. When you make edits locally you then try to manually recreate your work online? I ask because if you go about developing WP this way it's really easy to forget to update certain settings or create inconsistencies. For example, if you make 5 new pages locally in a certain order, you must do it in the exact same order online or else their page ID's will be inconsistent. Your code looks correct, but I suspect it has something to do with a discrepancy in the databases. – perpetualstudent Mar 18 '12 at 23:53
Are you sure the page id is the same and that you have published it? – Wyck Mar 19 '12 at 0:02
I will try and sync the databases from now on. There is no way to sync all of the settings I have locally to the online version such as permalinks structure or menu order or plugin settings is there. Can I only keep the databases in sync. – Anders Kitson Mar 19 '12 at 0:09
up vote 1 down vote accepted

have you tried get_page() ?

$page_id = 123; // 123 should be replaced with a specific Page's id from your site,

$page = get_page( $page_id ); // You must pass in a variable to the get_page function. 

echo '<h3>'. $page->post_title .'</h3>';// echo the page title

echo apply_filters('the_content', $page->post_content); // Get Content and retain Wordpress filters such as paragraph tags. 


don't forget to make sure you change the $page_id to match your live version

share|improve this answer
Thanks so much its working now. – Anders Kitson Mar 19 '12 at 18:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.