Title: Combining 2 Multiple Custom Fields
Last modified: August 19, 2016

---

# Combining 2 Multiple Custom Fields

 *  [blaumond](https://wordpress.org/support/users/blaumond/)
 * (@blaumond)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/combining-2-multiple-custom-fields/)
 * I am trying to combine 2 multiple custom fields to display photos and add 2 seperate
   links to the photos i.e. photo1 to link to link1 and photo2 to link to link2.
   This is what I did –
 * 1. Created a custom field “photo”
    2. Created a custom field “link” 3. 2 values
   each for “photo” and “link”
 * Code I used –
 *     ```
       <?php $links = get_post_meta($post->ID, "link", false) ?>
       <?php $photos = get_post_meta($post->ID, "photo", false) ?>
       <?php $title = get_the_title(); ?>
       <?php foreach($photos as $photo) {
       foreach($links as $link)
       echo "\n<p>\n <a href='".$link."' target='_blank'> <img src='".$photo."' alt='".$title."' title='".$title."' </a> \n</p>\n"; } ?>
       ```
   
 * This shows each image twice with the links. Can someone please help.
    Also if
   I have 3 values for “photo” and 1 value for “link” how can I link the second 
   photo only with the “link” value?

Viewing 1 replies (of 1 total)

 *  Thread Starter [blaumond](https://wordpress.org/support/users/blaumond/)
 * (@blaumond)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/combining-2-multiple-custom-fields/#post-1309224)
 * no one?

Viewing 1 replies (of 1 total)

The topic ‘Combining 2 Multiple Custom Fields’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * 1 reply
 * 1 participant
 * Last reply from: [blaumond](https://wordpress.org/support/users/blaumond/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/combining-2-multiple-custom-fields/#post-1309224)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
