I am building a single page theme, And I am having a problem with get_post_meta()

The Problem

This code bellow does not work, and I cannot see anything on the website as it's blank. Here is my index.php.

<?php get_header(); ?>

   global $query_string, $post;

   query_posts($query_string . "post_type=page&post_status=publish&posts_per_page=9");
   if ( have_posts() ) : while ( have_posts() ) : the_post();
   $home        = get_post_meta($post->ID, 'home', true);
   $about       = get_post_meta($post->ID, 'about', true);
   $contact     = get_post_meta($post->ID, 'contact', true);
   $services    = get_post_meta($post->ID, 'services', true);

<?php if ( $home ) : ?>
    <div id="home" class="borderline">
        <?php the_content(); ?>
<?php endif; ?>

<?php if ( $about ) : ?>
<section class="about-us" id="about-us">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <?php the_content(); ?>
<?php endif; ?>

<?php endwhile; endif; ?>
<?php get_footer(); ?>

The code above does not display anything.


  • How can I display my content using the code above?
  • Guidance on developing single page themes, going forward?
  • What page template hierarchy should I put my code?

My Pages look like this

Wp Pages

Thank you in advance.



1 Answer 1


Unless you have generated metafields called 'home', 'about', 'contact' and 'services' in functions.php using add_post_meta your calls to get_post_meta will always return false. So if you test if they are true later on, the answer is 'no' and nothing will be displayed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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