On parent page, I've got a grid of custom field values from child pages. All text fields work fine, but I'm having issues with the file URL fields: instead of the URL it returns attachment ID.

Here's the code I'm using to display all the fields:

    //get children of page 4 and display with custom fields

    'post_parent' => 4,
    'post_type' => 'page',

    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {

    while ($my_query->have_posts()) : $my_query->the_post(); ?>

Stripped down version, without any formatting:

    <?php $meta_one = get_post_meta($post->ID, 'doors', true); ?>
    <?php echo $meta_one; ?>

ACF's developer said I should be using get_field instead, but if I replace get_post_meta with get_field it doesn't even return the ID.

I've also tried adding URL parameter like this: <?php echo $meta_one['url']; ?> No change.

1 Answer 1


Here's how ACF keeps attachment data:

meta_id        post_id     meta_key        meta_value

971            931         doors           666
972            931         _doors          field_25

As you can see if you're using get_post_meta it will only ever be able to return you an ID. Since not using get_field you'll need to do the extra step of getting attachment metadata yourself:

$meta_one = get_post_meta($post->ID, 'doors', true);
$meta_url = wp_get_attachment_url( $meta_one );
echo $meta_url;
  • Of course I've done that, it's set to URL and returns the URL on the child page. Only having issues with getting the URL to show on the parent page.
    – Phantasmix
    Apr 3, 2013 at 4:16
  • Well, how are you getting the other fields? Should be no different. Did you examine your $meta_one? Not echo, but rather print_r($meta_one). Apr 3, 2013 at 5:38
  • The code I included in the original post is how I'm getting all the other fields into the parent. It works for text fields. -- print_r still prints the ID, not URL.
    – Phantasmix
    Apr 3, 2013 at 12:52
  • @Phantasmix I updated my answer, try it out. Apr 3, 2013 at 15:31
  • Awesome, thank you!! That works great. I didn't even think to look in the db, duh :) Thanks
    – Phantasmix
    Apr 4, 2013 at 5:03

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.