I'm using the ACF 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.
Maybe $attachment_id?
@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'); var_dump($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?
This here:
$image = get_sub_field('background_photo'); var_dump($image);
Returns this:
"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
Damn.
$image = get_post( get_sub_field('background-photo')); $attachment = get_post_meta($image->ID, true); echo $attachment;
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.
Bump. Anyone?
http://wordpress.stackexchange.com/questions/57411/how-to-get-both-image-attachment-id-and-url
@chrisburton Thanks a bunch bud!!!!! I saw that SE question last night, but obviously I was too tired to process.
This seems to work:
$attachment_id = get_sub_field('background_photo'); $image_attributes = wp_get_attachment_image_src( $attachment_id, $size ); echo $image_attributes[0];
Awesome. Glad you solved it.
I'm using the ACF 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:
Does anyone happen to know what I have to do to return the unique ID?
Thanks in advance.
Maybe $attachment_id?
@chrisburton How would I call that? I've tried this:
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:
@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?
This here:
Returns this:
"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.
My PHP is a bit rusty.
@chrisburton That isn't returning anything. :s
Damn.
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.
Bump. Anyone?
http://wordpress.stackexchange.com/questions/57411/how-to-get-both-image-attachment-id-and-url
@chrisburton Thanks a bunch bud!!!!! I saw that SE question last night, but obviously I was too tired to process.
This seems to work:
Awesome. Glad you solved it.