I’m using the [ACF](http://www.advancedcustomfields.com/docs/field-types/image/ “”) plugin, and am trying to work out how to return the image ID – as in a unique integer associated with that image.
I’m calling the URL like this:
< ?php the_sub_field('background_photo'); ?>
Does anyone happen to know what I have to do to return the unique ID?
Thanks in advance.
@chrisburton How would I call that? I’ve tried this:
< ?php the_sub_field('background_photo', $attachment_id); ?>
This just returns the image URL again.
My fault. Take a look at this: http://www.advancedcustomfields.com/docs/field-types/image/
But specifically this:
$image = get_field(‘image’);
@chrisburton I’m going to be honest. I have no clue what to do with that.
I do know that that value is stored in id, as the array example they show after that line. But how to retrieve it I have no idea.
What are you trying to do with this ID?
$image = get_sub_field(‘background_photo’);
“string(109) “http://localhost:8888/bit-simple/wp-content/uploads/2013/01/4acae3924ef6d13cdc85f14979a2ffe0da15cb05-copy.jpg” “
If I could just get the number inside that parentheses I’d be sorted!
@chrisburton I’m trying to use it as a selector. I need to give each image a unique ID.
$image = get_sub_field(‘background-photo’);
echo $image( array(‘id’));
My PHP is a bit rusty.
@chrisburton That isn’t returning anything. :s
$image = get_post( get_sub_field(‘background-photo’));
$attachment = get_post_meta($image->ID, true);
It’s really late here so I have to get going. If that doesn’t work, perhaps someone else can give it a shot. Otherwise I’d contact ACF directly.
@chrisburton Still nothing. Really appreciate the help and all, this has been killing me for hours. I don’t know what could be the problem.
You must be logged in to reply to this topic.
*May or may not contain any actual "CSS" or "Tricks".