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'm trying to display a custom field called 'my_custom_field' inside the loop:

$custom_array = get_post_custom( get_the_ID() );                    
echo $custom_array['my_custom_field'];

This code display "array". Should it not display the value of the custom field instead?

share|improve this question
up vote 3 down vote accepted

get_post_custom() will return an array of arrays. You need:

echo $custom_array['my_custom_field'][0];

Alternatively, you can use get_post_meta() with the $single flag as true:

echo get_post_meta( get_the_ID(), 'my_custom_field', true );
share|improve this answer

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.