0

I am grabbing two sets of custom meta and looping through the posts, order goes: custom meta1, posts, custom meta2. but for some reason the second set of custom meta wont show up if I add the posts loop.

does custom meta have to be within the loop? it seems to work if there is no loop call.

here is what my code looks like:

<div class="col_1 maxheight">
  <h1><a href="http://localhost/AMR/wp-content/uploads/2012/04/Title_Home.png"><img class="alignnone size-full wp-image-14" title="Title_Home" src="http://localhost/AMR/wp-content/uploads/2012/04/Title_Home.png" alt="" width="235" height="25" /></a></h1>
  <p class="BodyHeader">
    <?php if ( get_post_meta($post->ID, 'column1title', true) ) : ?>
    <?php echo get_post_meta($post->ID, 'column1title', true) ?>
    <?php endif; ?>
  </p>
  <?php if ( get_post_meta($post->ID, 'column1', true) ) : ?>
  <?php echo get_post_meta($post->ID, 'column1', true) ?>
  <?php endif; ?>
  <br /><br />
  <a href="http://localhost/AMR/wp-content/uploads/2012/04/eco-friendly_img.jpeg"><img class="alignnone size-full wp-image-11" title="eco-friendly_img" src="http://localhost/AMR/wp-content/uploads/2012/04/eco-friendly_img.jpeg" alt="" width="200" height="218" /></a>
</div>
<div class="separator maxheight"></div>



<div class="col_2 maxheight">
  <h1></h1>
  <p class="BodyHeader">Latest News</p>



<?php
$args = array( 'post_type' => 'post');
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
  while($post_query->have_posts() ) {
    $post_query->the_post();
?>
    <p class="BodySubHeader"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></p>
    <p><?php the_content(); ?></p>
    <?php
  }
}
?>
</div>

<div class="separator maxheight"></div>
<div class="col_3 maxheight">
  <h1></h1>
  <p class="BodyHeader">
  <?php if ( get_post_meta($post->ID, 'column3title', true) ) : ?>
  <?php echo get_post_meta($post->ID, 'column3title', true) ?>
  <?php endif; ?>
  </p>
  <?php if ( get_post_meta($post->ID, 'column3', true) ) : ?>
  <?php echo get_post_meta($post->ID, 'column3', true) ?>
  <?php endif; ?>
  <br /><br />
  <a href="http://localhost/AMR/wp-content/uploads/2012/04/MissionStatement_small_web.jpeg"><img class="alignnone size-full wp-image-15" title="MissionStatement_small_web" src="http://localhost/AMR/wp-content/uploads/2012/04/MissionStatement_small_web.jpeg" alt="" width="200" height="150" /></a>
</div>

it is on a page so I think $post->ID is setting ID to last post hence, not pulling any meta because there is no meta for last post. but not sure how to get around this.

1 Answer 1

0

You have to wp_reset_postdata() after your custom loop to restore the global $post variable.

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.