Wordpress & PHP (How do i call more than one Custom field)

Discussion in 'PHP' started by MafiaPenguin, May 3, 2010.

  1. #1
    Hi everyone!

    I am currently developing my own website dedicated to films (www.filmhammer.com) however i hit a road block when using php to insert Custom fields. I know the basics of PHP but i am completely confused with this.

    The problem is i can't figure out how to call more than one Custom Field. I plan on having about 6 for various features. It can obviously be done otherwise how would people be able to edit the wordpress pages so dramatically. I currently have one Custom Field active and i know how to place them in the code so they appear, but calling them from the database (if thats what i'm meant to be doing) is where i am stuck. My guess is it's rather simple. So is there anyone out there who can help?

    Here is the Code Im using to call the one custom field:
    <?php if (have_posts()) : while (have_posts()) : the_post(); $our_custom_field_variable = get_post_meta($post->ID, 'buyEbay', true);
    ?>
    Code (markup):
    And here is the code for where Im trying to display it.
    <div class="art-PostContent">
    
    <!-- Display the Custom Fields -->
    <div class="art-PostPurchaseE">
    <div class="buyEbay">
     <?php echo $our_custom_field_variable; ?>  
     </div>
    </div> 
    <div class="art-PostPurchaseA">
    <div class="buyAmazon">
     <?php echo $our_custom_field_variable; ?>  
     </div>
    </div>
    Code (markup):
    Obviously i am trying to display two, but have only called one. I need to know how to call more than one as what i have tried doesn't work so far.

    Here is the post i am testing this on. And as you can see, both custom fields display as the one being called at the top of my code.

    Thanks for your time and apologies if what Im asking doesn't really make sense, if you think you can help but not sure what im on about please ask. Replying, if you know (at all) anything that you think may solve this issue would be much appreciated.

    Also if it helps, here is the entire Code from the php file

    <?php get_header(); ?>
    <div class="art-contentLayout">
    <div class="art-content">
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); $our_custom_field_variable = get_post_meta($post->ID, 'buyEbay', true);
    ?>
    
    
    <div class = "art-headadvert">
    <div style="float:left;">
    <?php echo show_ad_camp_3(); ?></div> 
    <div style="float:right;">
    <?php echo show_ad_camp_3(); ?></div> 
    <?php echo show_ad_camp_3(); ?>
    </div>
    <?php if ($prev_link || $next_link): ?>
    <div class="art-Post">
        <div class="art-Post-body">
    <div class="art-Post-inner art-article">
    
    <div class="art-PostContent">
    
    <div class="navigation">
    	<div class="alignleft"><?php echo $prev_link; ?></div>
    	<div class="alignright"><?php echo $next_link; ?></div>
    </div>
    
    </div>
    <div class="cleared"></div>
    
    
    </div>
    
    		<div class="cleared"></div>
        </div>
    </div>
    
    <?php endif; ?>
    <div class="art-Post">
        <div class="art-Post-body">
    <div class="art-Post-inner art-article">
    <?php ob_start(); ?>
    <div class="art-PostRater">
    <?php wp_gdsr_render_article(10, false); ?></div>
    <h2 class="art-PostHeader">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>">
    <?php the_title(); ?></a></h2>
    </a>
    </h2>
    
    <?php $metadataContent = ob_get_clean(); ?>
    <?php if (trim($metadataContent) != ''): ?>
    <div class="art-PostMetadataHeader">
    <?php echo $metadataContent; ?>
    
    </div>
    <?php endif; ?>
    <?php $icons = array(); ?>
    <?php if (!is_page()): ?><?php ob_start(); ?><?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?><?php endif; ?><?php if (0 != count($icons)): ?>
    </div>
    <?php endif; ?>
    
    <div class="art-PostContent">
    
    <!-- Display the Custom Fields -->
    
    <div class="art-PostPurchaseE">
    <div class="buyEbay">
     <?php echo $our_custom_field_variable; ?>  
     </div>
    </div> 
    <div class="art-PostPurchaseA">
    <div class="buyAmazon">
     <?php echo $our_custom_field_variable; ?>  
     </div>
    </div> 
    
    
    
             <?php if (is_search()) the_excerpt(); else the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?>
              <?php if (is_page() or is_single()) wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
            
    </div>
    <div class="cleared"></div>
    <?php ob_start(); ?>
    <?php $icons = array(); ?>
    <?php if (!is_page()): ?><?php ob_start(); ?><?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (!is_page() && get_the_tags()): ?><?php ob_start(); ?><img src="<?php bloginfo('template_url'); ?>/images/PostTagIcon.png" width="18" height="18" alt="" />
    <?php the_tags(__('Tags:', 'kubrick') . ' ', ', ', ' '); ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (!is_page() && !is_single()): ?><?php ob_start(); ?><img src="<?php bloginfo('template_url'); ?>/images/PostCommentsIcon.png" width="17" height="15" alt="" />
    <?php comments_popup_link(__('No Comments »', 'kubrick'), __('1 Comment »', 'kubrick'), __('% Comments »', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (0 != count($icons)): ?>
    <div class="art-PostFooterIcons art-metadata-icons">
    <?php echo implode(' | ', $icons); ?>
    
    </div>
    <?php endif; ?>
    <?php $metadataContent = ob_get_clean(); ?>
    <?php if (trim($metadataContent) != ''): ?>
    <div class="art-PostMetadataFooter">
    <?php echo $metadataContent; ?>
    
    </div>
    <?php endif; ?>
    
    </div>
    
    		<div class="cleared"></div>
        </div>
    </div>
    
    <?php comments_template(); ?>
    <?php endwhile; ?>
    <?php else: ?>
    <h2 class="center"><?php _e('Sorry, no posts matched your criteria.', 'kubrick'); ?></h2>
    <?php endif; ?>
    
    </div>
    <?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
    </div>
    <div class="cleared"></div>
    
    <?php get_footer(); ?>
    Code (markup):
    Thanks :)
     
    MafiaPenguin, May 3, 2010 IP