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:
<?php
//get children of page 4 and display with custom fields
$args=array(
'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.
Here’s how ACF keeps attachment data:
As you can see if you’re using
get_post_meta
it will only ever be able to return you an ID. Since not usingget_field
you’ll need to do the extra step of getting attachment metadata yourself: