0

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?

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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