Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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.