Title: Retrieving values using get_post_meta
Last modified: August 31, 2016

---

# Retrieving values using get_post_meta

 *  Resolved [tomwhita](https://wordpress.org/support/users/tomwhita/)
 * (@tomwhita)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/retrieving-values-using-get_post_meta/)
 * Ive create a couple of fields and attached them to the custom post type “project”.
   I’ve tried to embed field values in a page template for projects but the data
   is not retrieved. I’ve tried using a simple, non-carbon custom field and the 
   code below works fine. What am i doing wrong?
 * `<time>Start Date: <?php echo get_post_meta($post->ID, 'project_start_date', 
   true); ?></time>`
 * [https://wordpress.org/plugins/carbon-fields/](https://wordpress.org/plugins/carbon-fields/)

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

 *  Plugin Author [htmlBurger](https://wordpress.org/support/users/htmlburger/)
 * (@htmlburger)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/retrieving-values-using-get_post_meta/#post-7187074)
 * Hi [@tomwhita](https://wordpress.org/support/users/tomwhita/),
 * You haven’t posted the definition of your fields, but it appears you’re missing
   an underscore at the beginning of the field. Let us explain.
 * You have generally 2 ways of retrieving a post meta field:
 * 1. Using `get_post_meta()`
    2. Using the Carbon Fields function `carbon_get_post_meta()`.
 * We recommend using the second one. Your code would then be:
 *     ```
       <time>Start Date: <?php echo carbon_get_post_meta($post->ID, 'project_start_date'); ?></time>
       ```
   
 * and in case you still want to use `get_post_meta()`, you will have to prefix 
   the field with an underscore, like this:
 *     ```
       <time>Start Date: <?php echo get_post_meta($post->ID, '_project_start_date', true); ?></time>
       ```
   
 * You might be wondering why the underscore prefix? Well, you’ve probably seen 
   the default Custom Fields interface in WordPress? If you don’t prefix your post
   meta fields with an underscore, they will be shown in that interface as well.
   That is why most custom fields plugins add that prefix to their fields. And WordPress
   core also does that for internal post meta (like `_thumbnail_id` that is used
   for the post featured image).
 * Please, don’t hesitate to let us know if you have any other questions.
 *  Thread Starter [tomwhita](https://wordpress.org/support/users/tomwhita/)
 * (@tomwhita)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/retrieving-values-using-get_post_meta/#post-7187097)
 * Thanks. This makes sense. I wasn’t able to find the answer in your docs. Was 
   it in there? Perhaps I missed it.
 * I changed the code to your preferred solution and it works. I also added an esc_html.
   Below is the complete solution for showing a field value within a loop in case
   anyone is interested:
 * Assumes you’ve already fetched the posts:
 * `<?php $yourfieldvariable = carbon_get_post_meta($post->ID, 'your_field_key');
   echo esc_html( $yourfieldvariable ); ?>`
 *  Plugin Author [htmlBurger](https://wordpress.org/support/users/htmlburger/)
 * (@htmlburger)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/retrieving-values-using-get_post_meta/#post-7187136)
 * Hi [@tomwhita](https://wordpress.org/support/users/tomwhita/),
 * It appears you’ve missed it – it exists in the documentation. Basically there
   is a different data retrieval function for each container type – it can be found
   under the “Accessing field values” section in the documentation article of the
   corresponding container.
 * For example, you will easily notice it in the Post Meta container article in 
   the documentation: [http://carbonfields.net/docs/containers-post-meta/](http://carbonfields.net/docs/containers-post-meta/)

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

The topic ‘Retrieving values using get_post_meta’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/carbon-fields_cacbcc.svg)
 * [Carbon Fields](https://wordpress.org/plugins/carbon-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/carbon-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/carbon-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/carbon-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/carbon-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/carbon-fields/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [htmlBurger](https://wordpress.org/support/users/htmlburger/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/retrieving-values-using-get_post_meta/#post-7187136)
 * Status: resolved