Title: Output Different Custom Fields Separately
Last modified: August 20, 2016

---

# Output Different Custom Fields Separately

 *  Resolved [maxbuxfiy](https://wordpress.org/support/users/maxbuxfiy/)
 * (@maxbuxfiy)
 * [14 years ago](https://wordpress.org/support/topic/output-different-custom-fields-separately/)
 * I have two custom fields in a post,
 * customfiled-a
    customfiled-b
 * in my single.php file, I wish to place each output in a div class …
 *     ```
       <div class=“a”>
       customfiled-a
       </div>
       ```
   
 *     ```
       <div class=“b”>
       customfiled-b
       </div>
       ```
   
 * How can I do this? I have tried `Get_post_meta()` but it prints out both as expected
   🙂

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years ago](https://wordpress.org/support/topic/output-different-custom-fields-separately/#post-2744694)
 * Have you tried it like this (inside the loop):
 *     ```
       <?php
       $customfiled_a = get_post_meta($post->ID, 'customfiled-a', true);
       if ($customfiled_a != '' ) : ?>
       <div class="a">
       <?php echo $customfiled_a; ?>
       </div>
       <?php endif; ?>
       ```
   
 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [14 years ago](https://wordpress.org/support/topic/output-different-custom-fields-separately/#post-2744695)
 * Snap!
 * Get **single** post meta!
 * get_post_meta( $post_ID, $key , $single );
 *     ```
       <div class='a'><?php echo get_post_meta(get_the_ID(), 'field-a', true); ?></div>
       <div class='b'><?php echo get_post_meta(get_the_ID(), 'field-b', true); ?></div>
       ```
   
 * HTH
 * David
 *  Thread Starter [maxbuxfiy](https://wordpress.org/support/users/maxbuxfiy/)
 * (@maxbuxfiy)
 * [14 years ago](https://wordpress.org/support/topic/output-different-custom-fields-separately/#post-2744702)
 * I have tried the two and the result comes up blank. It only seems to work with
   get_post_meta(), could I be doing something wrong?
 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [14 years ago](https://wordpress.org/support/topic/output-different-custom-fields-separately/#post-2744705)
 * Try:
 *     ```
       <?php global $post; ?>
       <div class='a'><?php echo get_post_meta($post->ID, 'customfiled-a', true); ?></div>
       <div class='b'><?php echo get_post_meta($post->ID, 'customfiled-b', true); ?></div>
       ```
   
 * HTH
 * David
 *  Thread Starter [maxbuxfiy](https://wordpress.org/support/users/maxbuxfiy/)
 * (@maxbuxfiy)
 * [14 years ago](https://wordpress.org/support/topic/output-different-custom-fields-separately/#post-2744706)
 * Sorry guys, they are both working. It was an issue of “too much caching”.
 * Cleared all the caches and things are OK.
 * Thank you
 *  [oezidi](https://wordpress.org/support/users/oezidi/)
 * (@oezidi)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/output-different-custom-fields-separately/#post-2745059)
 * Pls I am new to wordpress. Can someone please tell me where to locate the file
   where I can include the php shortcode above? I am using custom field template
   and advanced custom field plugins

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Output Different Custom Fields Separately’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 4 participants
 * Last reply from: [oezidi](https://wordpress.org/support/users/oezidi/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/output-different-custom-fields-separately/#post-2745059)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
