• Hi,

    I’m using get_post_meta to retrieve some custom field data “project year” within a custom loop that creates a gallery with post thumbnails and excerpts for a specified category.

    The custom field variable “project year” is overlayed as a span over each thumbnail.

    For some reason, get_post_meta is interfering with the loop. The first post in the category that it retrieves has the year properly overlayed over the thumbnail, however, instead of retrieving the rest of the posts, the first result is repeated in place of the other posts without the “project year”.

    If anyone can suggest how to approach this unexpected problem, I would greatly appreciate it.

    <?php foreach (get_categories(array('hide_empty'=>false, 'include'=>$cat)) as $category)://Check to see if posts exist
    if ($category->count > 0){ // if posts exist then execute loop
    
    $args=array(
    'post_status' => 'publish',
    'post__not_in'=> get_option('sticky_posts'),
    'category__in'=> array($cat),
    'order'=> 'DESC',
    );
    
    $do_not_duplicate = array();
    $my_query = new WP_Query($args);
    
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <li class="browser-panel">
    
    	<div class="project-thumbnails">
    
    	  <a class="project-thumbnails-link" href="<?php echo post_permalink(); ?>" rel="">
    
    	<?php if ( has_post_thumbnail() )//Insert featured thumbnail for project or default if not specified
    	the_post_thumbnail( 'archive-thumbnail' ); else
    	echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/archive_default_thumb_small.png" alt="" title="default image" />'?>
    							</a>					
    
    	<span class="project-meta">
    		<?php $key="project year";
    			       $postid = get_the_ID(); ?> 
    
    		<span class="project-year">
    		<?php if ( get_post_meta($postid, $key, true)) : ?>
    		<?php echo  get_post_meta($postid, $key, true) ?>
    	        <?php endif; ?>
    
    		</span>
    	</span>
    
    			</div>
    			<h5 class="project-title">
    			<a>" rel="bookmark"><?php trim_title(); ?></a>
    			</h5>
    			<div class="project-summary">
    
    			<?php echo my_excerpts(); ?>
    														<span class="project-more"><a>">Read More</a></span>
    			</div>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tnoguchi

    (@tnoguchi)

    A follow-up. I looked at the underlying html being produced. There’s actually nothing wrong with it technically. Each of the thumbnails, excerpts and post-meta is being produced. For some reason this seems to be a bug in Chrome?

    FF seems to be rendering the page more or less correctly. However, even though the code is correct, Chrome is repeating the first li panel content over and over.

    Thread Starter tnoguchi

    (@tnoguchi)

    Okay, this was totally a CSS issue and not, what I had earlier thought, a problem with my PHP.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_post_meta stomping on custom loop results…’ is closed to new replies.