How to use more than one Custom Field on the same Post.

Discussion in 'WordPress' 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 Custom fields.

    Basically Im using them to add more sections to each Post. For example, I'm aiming to have a "Buy the film" section with 2 areas dedicated to two different websites. For this i need to use two different Custom Fields. One for 'Ebay' and one for 'Amazon'. I have created both fields using the More Fields plugin.

    The problem is i can't figure out how to call more than one Custom Field. It can obviously be done , and 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 called and not the ones being used.

    http://www.filmhammer.com/batman-begins

    Thanks for your time and apologies for the over complicated question. Replying, if you know (at all) anything that you think may solve this issue would be much appreciated.
     
    Last edited: May 3, 2010
    MafiaPenguin, May 3, 2010 IP
  2. rilwis

    rilwis Peon

    Messages:
    104
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to call the function get_post_meta 2 times:

    
    $buy_ebay = get_post_meta($post->ID, 'buyEbay', true);
    $buy_amazone = get_post_meta($post->ID, 'buyAmazon', true);
    
    PHP:
    and then echo them. That's all.
     
    rilwis, May 4, 2010 IP
  3. MafiaPenguin

    MafiaPenguin Guest

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    How do i echo them, sorry :p
     
    MafiaPenguin, May 13, 2010 IP