Skip Navigation

[Resolved] Multiple image fields images not showing

This support ticket is created 3 years 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 3 years ago.

Assisted by: Waqar.

Author
Posts
#2235581

I am trying to: Add a custom content instance with a multiple image field

Link to a page where the issue can be seen:
hidden link

I expected to see: A gallery of images

Instead, I got: No images

#2235857

Hi,

Thank you for contacting us and I'd be happy to assist.

The gallery shortcode that you're using in your content template requires image IDs to work, whereas, in Toolset's image type fields, the image's URL is saved and not the IDs.

To make this work, you'll need a custom shortcode, that can get the image URLs from the field and then return their respective image IDs.

The following 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 the active theme's "functions.php" file.


function get_image_ids_from_field_func( $atts )
{
	$a = shortcode_atts( array(
		'field' => '',
		'separator' => ','
	), $atts );

	$field_value = types_render_field( $a['field'], array( "output" => "raw", "separator" => $a['separator'] ) );

	if(!empty($field_value)) {
		$field_value_arr = explode($a['separator'], $field_value);
		foreach ($field_value_arr as $field_value_item) {
			$image_ids[] = attachment_url_to_postid( $field_value_item );
		}

		if( !empty($image_ids) ) {
			$image_ids_str = implode($a['separator'], $image_ids);
			return $image_ids_str;
		}
	}
}
add_shortcode( 'get_image_ids_from_field', 'get_image_ids_from_field_func' );

Next, please add "get_image_ids_from_field" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

After that, you'll be able to use this new shortcode, within your gallery shortcode, like this:


[gallery type="rectangle" ids="[get_image_ids_from_field field='gallery-photo' separator=',']"]

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