Skip Navigation

[Resolved] How do display ACF Image field in a Toolset view

This support ticket is created 4 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 4 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1793233

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

#1795045

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