Tell us what you are trying to do?
I have a custom field which is an ACF Pro image field. I want to be able to load this field into my Toolset view but all that generated and shows in the front end is the ID number of the image
Is there any documentation that you are following?
I've tried looking through all of the forum posts about this issue (of which there are many), and I have tried to implement them, but they do not work
I understand that in order to do this I will need to create a shortcode in my functions.php file, however I have tried using the sample code suggested in a few different forum posts on this website, but they do not work. Most of them are dated a few years ago so possibly that is why. Please can someone provide me with the code I would need to add to my functions.php file which would allow me to obtain the image url from the ID number which is currently displaying?
Thank you very much in advance for your help,
Keith
Hi Keith,
Thank you for contacting us and I'd be happy to assist.
On my test website, I was able to get the image URL, using this custom shortcode:
add_shortcode('get_image_URL_by_ID', 'get_image_URL_by_ID_fn');
function get_image_URL_by_ID_fn( $atts ) {
$data = shortcode_atts( array(
'field' => ''
), $atts );
if(!empty($atts['field'])) {
$image_ID = do_shortcode('[acf field="'.$atts['field'].'"]');
$URL = wp_get_attachment_image_src($image_ID, 'full');
if($URL) {
return $URL[0];
}
}
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.
In your view or content template, you can use this custom shortcode like this:
[get_image_URL_by_ID field="image_field_name"]
Please replace "image_field_name" with the actual name of your ACF image field.
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar