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?

1 Answer 1


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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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