Title: get-posts &#8211; how to get custom fields data
Last modified: August 21, 2016

---

# get-posts – how to get custom fields data

 *  [Josh Ford](https://wordpress.org/support/users/joshford1maccom/)
 * (@joshford1maccom)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/get-posts-how-to-get-custom-fields-data/)
 * I’m using this on my home page to display a featured post
 *     ```
       <?php $posts = get_posts( array( 'category' => 23 ) ); ?>
       	    <?php foreach ($posts as $post): ?>
       	        <li>
       	            <a href="<?php echo get_page_link( $post->ID ); ?>" >
       			<h1>Featured Post</h1>
       			<?php echo get_the_post_thumbnail($post->ID); ?>
       			<ul>
       				<li><?php echo $post->post_title; ?></li>
       				<li><?php echo $post->post_excerpt; ?></li>
       			</ul>
       		    </a>
       	        </li>
       	    <?php endforeach; ?>
       ```
   
 * It works as required but I need to also display in the list the key and value
   from 2 custom fields for that post and can’t figure it out. Searched the codex
   and forums but getting confused as per the correct syntax. Any help greatly appreciated.

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

 *  [christopherross](https://wordpress.org/support/users/christopherross/)
 * (@christopherross)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/get-posts-how-to-get-custom-fields-data/#post-3931239)
 * Hi Josh,
 * You’ll want to look at [http://codex.wordpress.org/Function_Reference/get_post_meta](http://codex.wordpress.org/Function_Reference/get_post_meta)
   and the code $meta_values = get_post_meta( $post_id, $key, $single ); which will
   return the values you’re looking for.
 * For example $meta_values = get_post_meta( $post-ID, ‘UNIQUE_KEY_NAME’, true );
   will return what you’re looking for.
 *  Thread Starter [Josh Ford](https://wordpress.org/support/users/joshford1maccom/)
 * (@joshford1maccom)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/get-posts-how-to-get-custom-fields-data/#post-3931377)
 * Thanks, that helped make sense of it all.

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

The topic ‘get-posts – how to get custom fields data’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Josh Ford](https://wordpress.org/support/users/joshford1maccom/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/get-posts-how-to-get-custom-fields-data/#post-3931377)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
