WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to get the value of a custom field, using code like get_post_meta($post->ID, 'company', true);. Is there a way to get the name of the custom field?

share|improve this question
up vote 3 down vote accepted

to get a post custom fields name you can use get_post_custom


$post_meta = get_post_custom($post->ID);
foreach ( $post_meta as $key => $value )
    echo $key . " => " . $value . "<br />";

this will print a list of custom_field_name => custom_field_value

share|improve this answer
+1 for clear answer.:) – Ramkumar Jul 1 '11 at 6:24

if you only want to get the name, you can use get_post_custom_keys


  $custom_field_keys = get_post_custom_keys();
  foreach ( $custom_field_keys as $key => $value ) {
    $valuet = trim($value);
      if ( '_' == $valuet{0} )
    echo $key . " => " . $value . "<br />";

prints something like this:

0 => mykey
1 => yourkey
share|improve this answer
I just hope an explanation was given by that (-1) down vote.. – Reigel Jul 1 '11 at 6:52
Fail to see what's wrong with this answer, +1 from me to cancel out the downvote. – Mark Duncan Jul 1 '11 at 10:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.