Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently working my way through some custom posts (for the first time).

I'm managing to return the bits I need using this

            <div class="pagered">
              <h1 class="page-title"><?php the_title(); ?></h1>
              <?php the_content(); ?>
              <?php query_posts('post_type=case_studies'); if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
              <p><?php echo get_post_meta($post->ID, "_Description", true); ?></p>
              <p><?php echo get_post_meta($post->ID, "_Requirement", true); ?></p>
              <p><?php echo get_post_meta($post->ID, "_Solution", true); ?></p>
               <?php endwhile; wp_reset_query(); ?>
            </div>
            <?php if ( is_active_sidebar('pages-sidebar')) { ?>

But it pulls all of the _Description, _Requirement and _Solution. What do I need to do to make it only return the custom post stuff from that page?

Also should I be putting the_title and the_content in that query_posts too?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

your main problem is

              <?php query_posts('post_type=case_studies'); if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

This means if there are posts, then while there are posts, get from the current post. After processing, it will just keep iterating through the posts.

Delete this line and the end while line.

Instead, use this

<p><?php echo get_post_meta(get_the_ID(), "_Description", true); ?></p>

This gets the current id of the current post.

Having said that, please do some validation of the results you get from get_post_meta to ensure that there are results before echoing it out.

share|improve this answer
add comment

Your Answer

 
discard

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.