• I am creating a loop to pull the posts from wordpress. I am trying to get the loop to get the custom field called ‘itemNum’ so that I can use that to generate the link to the image for that post. So far I am not having any luck. Here is my code:

    <div id="product-grid">
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    			<div class="product">
    				<a href="<?php the_permalink(); ?>" rel="shadowbox[<?php single_cat_title(); ?>];width=600" title="<?php the_title(); ?>">
    				<img src="<?php bloginfo('url'); ?>/images/<?php get_post_custom_values('itemNum'); ?>.jpg">
    				<p><?php the_title(); ?></p></a>
    			</div>
    
    		<?php endwhile; ?>
    		<?php endif; ?>
    </div>
Viewing 1 replies (of 1 total)
  • Didn’t test this but try:

    <div id="product-grid">
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
    		$itemnum = get_post_meta($post->ID, 'itemNum', true);
    		if ($itemnum) {
    		?>
    
    			<div class="product">
    				<a href="<?php the_permalink(); ?>" rel="shadowbox[<?php single_cat_title(); ?>];width=600" title="<?php the_title(); ?>">
    				<img src="<?php bloginfo('url'); ?>/images/<?php echo $itemnum; ?>.jpg">
    				<p><?php the_title(); ?></p></a>
    			</div>
    
    		<?php
    		}
    		endwhile; ?>
    		<?php endif; ?>
    </div>

Viewing 1 replies (of 1 total)

The topic ‘Get Custom Field in Loop’ is closed to new replies.