Title: Custom Fields Help&#8230;
Last modified: August 19, 2016

---

# Custom Fields Help…

 *  [ultimat1](https://wordpress.org/support/users/ultimat1/)
 * (@ultimat1)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/)
 * I have a WP site that uses custom fields for many different things, including
   product descriptions on the single.php page. Normally with my other sites I would
   just include: <?php the_meta(); ?> and list them all – but I cannot do this with
   this site as there are many other fields that are completely unrelated to the
   description.
 * I would like to have just the fields for descriptions show up on this page, and
   not the 20 others. How can I code this to display only selected custom fields
   on this page?
 * Thanks

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

 *  [halfascissor](https://wordpress.org/support/users/halfascissor/)
 * (@halfascissor)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2055780)
 * try
    [http://codex.wordpress.org/Custom_Fields#Advanced_Techniques_for_Custom_Fields](http://codex.wordpress.org/Custom_Fields#Advanced_Techniques_for_Custom_Fields)
 *  Thread Starter [ultimat1](https://wordpress.org/support/users/ultimat1/)
 * (@ultimat1)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2055845)
 * Okay, thanks for that – it helped me accomplish what I was hoping for.
    So it
   now looks like this in “single.php”:
 * **Brand: **<?php $key=”Brand”; echo get_post_meta($post->ID, $key, true); ?>
 * But what it doesn’t say is how to get the $key name to come up as well.
 * So if there is no brand name available then I still have the word “Brand:” with
   a blank space after.
 * What I would like to do is get the name of the ($key) to come before the meta
   data dynamically, so that if there is no brand entered into the custom field,
   it would show nothing at all for that string.
 * Is there a way to do this?
 *  [sylvain.d](https://wordpress.org/support/users/sylvaind/)
 * (@sylvaind)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2055856)
 * I’m not sure it’s the best way to do it but here is what i use
    `<?php $key =
   get_post_meta($post->ID, 'YOURCUSTOMFIELD', true) ; if (!empty($key)) { ?>Brand:
   <?php echo ($key)} ?>`
 *  Thread Starter [ultimat1](https://wordpress.org/support/users/ultimat1/)
 * (@ultimat1)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2055860)
 * I copied the code you provided and changed the ‘YOURCUSTOMFIELD’ part to the 
   name of my custom field and returned an error.
 * Parse error: syntax error, unexpected ‘}’, expecting ‘,’ or ‘;’ in XXXXX/XXXXXX/
   XXXXX/single.php on line 434
 * Thanks for trying to help, though. Maybe I did something wrong?
 *  [fonglh](https://wordpress.org/support/users/fonglh/)
 * (@fonglh)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2055861)
 * add a semicolon after echo ($key)};
 *  Thread Starter [ultimat1](https://wordpress.org/support/users/ultimat1/)
 * (@ultimat1)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2055863)
 * Didn’t work. 🙁
 * Thanks anyway.
 *  [sylvain.d](https://wordpress.org/support/users/sylvaind/)
 * (@sylvaind)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2055871)
 * hmmm I’m really bad at troubleshooting php… I’ll post the code I use without 
   any modifications. Maybe it will be more helpfull
    `<?php $email = get_post_meta(
   $post->ID, 'ccio_email', true) ; if (!empty($email)) { ?><li>Courriel: <?php 
   echo get_post_meta($post->ID, 'ccio_email', true) ; ?></li><?php } ?>`
 *  Thread Starter [ultimat1](https://wordpress.org/support/users/ultimat1/)
 * (@ultimat1)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2055884)
 * Unfortunately so am I, lol.
 *  Thread Starter [ultimat1](https://wordpress.org/support/users/ultimat1/)
 * (@ultimat1)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2056094)
 * Is there a way to get the name of the ($key) to come before the meta data dynamically,
   so that if there is no brand entered into the custom field, it would show nothing
   at all for that string?
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2056096)
 * Try using the `get_post_custom()` function ([Codex ref](http://codex.wordpress.org/Function_Reference/get_post_custom)),
   which returns an associative ( ‘key’ => ‘value’ ) array of all post metadata.
   e.g.
 *     ```
       $mypostmeta = get_post_custom();
       ```
   
 * Then, you can do whatever you need to, with your specific meta keys.
 *  Thread Starter [ultimat1](https://wordpress.org/support/users/ultimat1/)
 * (@ultimat1)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2056098)
 * That would be perfect but instead of showing the name of the key (i.e. – “Brand”)
   it shows a numeric value from 0-whatever.
 * So if the custom field metadata is “Budweiser” it shows “0 => Budweiser”.
 * I need it to show “Brand => Budweiser”. And so on with any other keys that are
   specified. Almost there, though. Any idea how to change the number to the actual
   key name?
 * Thanks everyone for your help, I do appreciate it!
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2056099)
 * > So if the custom field metadata is “Budweiser” it shows “0 => Budweiser”.
   > I need it to show “Brand => Budweiser”.
 *     ```
       $postmeta = get_post_custom();
       $mymetakey = $postmeta['my-meta-key'];
       $mymetavalue = $mymetakey[0];
       ```
   
 *  Thread Starter [ultimat1](https://wordpress.org/support/users/ultimat1/)
 * (@ultimat1)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2056143)
 * Well I figured this out, so I decided to share just in case anyone else has this
   issue.
 * Instead of trying to select which keys I wanted to show, I decided to try to 
   focus on the ones I DIDN’T want to show, and specified that like so (just replace“
   yourkey” with the name of the key that you do not want to show to visitors, all
   other keys:values will show.) :
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * I don’t know that this is the best way to do it, but it worked for me. Thanks
   to all who were kind enough to offer help!
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2056144)
 * How to post code in WordPress forum topics: [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)

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

The topic ‘Custom Fields Help…’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 14 replies
 * 6 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/custom-fields-help-5/#post-2056144)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
