Retreiving src attribute of multiple images in a php array

77 Views Asked by At

I have the code as follows for creating a custom module in Beaver Builder:

'my_multiple_photos_field' => array(
'type'          => 'multiple-photos',
'label'         => __( 'Multiple Photos Field', 'fl-builder' )

),

Now i want to display all the images in this array. This is not working.

<div class="fl-example-image">
<?php echo "<img src='".$settings->my_multiple_photos_field_src."'>" 
?>

1

There are 1 best solutions below

0
On

this setting field from Beaver Builder:

'my_multiple_photos_field' => array(
    'type'          => 'multiple-photos',
    'label'         => __( 'Multiple Photos Field', 'fl-builder' )
),

will give you an array of ids --> attachment-ids.

so if you need those images, you have to get the url for the src-tag.

with: wp_get_attachment_url( int $attachment_id )

$output = '';
$output = '<div class="fl-example-image">';
foreach($settings->my_multiple_photos_field_src as $imageid){
    $src = wp_get_attachment_url( (int) $imageid );
    $output .= "<img src='" . $src . "' />";
}  
$output .= '</div>'; // close imageholder 

echo $output;

The code goes into your frontend.php, as described in the docs from beaver builder: Custom module developer guide