I have been trying a way round my latest WordPress problem all morning and I feel now is the right time to shout and ask for help.

I have been trying to create a people directory, I'm there except for the overall listing page which I have decided to be rows of 5 images followed by the persons name below each image, followed by another a row etc...

Each persons page has a set of custom fields one of which is name and another is mainimage the idea being that with the following code I can pull the image along with the name from the child pages of people and display them all on the one page with the image and name linked to the permalinkof the specific child page.

    // Get the page's children
    $args = array( 'numberposts' => 100, 'child_of' => 35, 'post_type' => page, );
    $children = get_pages( $args );

if (!empty($children)) { 
    echo '';
    foreach($children as $child) {
        // Get the 2 meta values from the child page
        $main_image = get_post_meta($child->ID, 'main_image', true); 
        $name = get_post_meta($child->ID, 'name', true); 

        // Display the meta values
        echo '<br />';
        echo $main_image;
        echo '<br />';
        echo $name;
    echo '';

It works kind of, but I'm getting a number for the image as opposed something that outputs to an image. Upon checking the custom field I have found the image value is a number, looks to me like media ID.

I need to either be able to interpret the ID within the people page as an image or a way to make sure actual urls are being put into the custom field values so I can use standard img src html to output the image.

I am using Advanced Custom Fields to create the fieldsets for the people page as well as the individual person pages.

Any help would be greatly appreciated as I have tried several variations of the code above but just cannot get the number to change in to the associated image.

2 Answers 2


Use wp_get_attachment_image( $id ).

Sample code:

print wp_get_attachment_image( 
    array ( 80, 80 ),
    array ( 'alt' => 'portrait' )
  • That works well. Thanks. But I'm getting a number 1 printed after each image and how can I specify a custom size of the images (190x220)?
    – Ben
    Sep 22, 2012 at 13:27
  • Not sure about the extra number, I cannot test right now. For custom image sizes use add_image_size().
    – fuxia
    Sep 22, 2012 at 13:36
  • Thanks again... Got it working correctly, don't quite understand what I did to stop the number displaying but it's not anymore :)
    – Ben
    Sep 23, 2012 at 18:56

When using get_field() or the_field() and the Image ID is returned instead of the expected return value, this is a sign that acf_add_local_field_group() was not run. Therefore ACF is pulling the raw value from the database but has no way to determine in which format you want it.

To resolve the issue, ensure that acf_add_local_field_group() is run from the init hook, not one of the admin_* hooks.

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.